Home > Blockchain >  Selecting more than 1 F'string in dataframe. python?
Selecting more than 1 F'string in dataframe. python?

Time:03-22

I have a sample code using google calendar API that requires data to be a string value. Instead of manually typing strings each time the data frame is changed I use df.iat. This is what I have so far and works fine for a single value.

Create an event
"""
event = {
  'summary':f'{df.iat[0,0]}',
  'description': f'{df.iat[0,1]}',
  'start': {
    'date': '2022-04-04',
  },
  'end': {
    'date': '2022-04-04',

which prints out

summary = Order
description = Plastic Cups
date 04-04-2022

But I need to pull multiple values into a string. How do I perform this to work properly for example in the description

I want to do f'{df.iat[1,1]}',f'{df.iat[0,1]}'
which would print out description = 7000  Plastic Cups

but I get errors using this and I've tried dfiloc, I've also tried just a sample

(("test"),(f'{df.iat[0,1]}')

this only prints off the 'test' portion and not the df.iat string

I've been stuck at this for hours any help would be appreciated.

CodePudding user response:

f-strings in Python, also known as Literal String Interpolation, can handle multiple variables at the same time. For example:

orderID = 012345
orderName = "foo"

message = f"Your order {orderName} with orderID {orderID} was registered!"

If you print the aforementioned message:
Your order foo with orderID 012345 was registered!

For more info regarding this: PEP-0498

  • Related