Skip to main content

All Questions

Tagged with
0 votes
1 answer
151 views

Python function not working properly with f'{col}'

EDIT SUMMARY So I have: p1 dataframe with the prices and the returns of n-financial instrument of the last 5 years: Date a_price b_price a_ret b_ret 0 2018-04-13 6.335 ...
CristinaK's user avatar
0 votes
1 answer
287 views

How to format f-strings from dataframe with curly brackets in the dataframe?

How to format f-strings from dataframe with curly brackets in the dataframe? Text in a dataframe that has curly brackets { and } in the text, which is intended to trigger f-string formatting of ...
user1574881's user avatar
0 votes
1 answer
965 views

How can I use f string to call a list index?

I've read this issue, but it didn't work here. I've a dataframe and want to add new column with the month index considering the position they've in a list. I don't want to create an if condition ...
polo's user avatar
  • 185
1 vote
1 answer
2k views

f-string formatting in pandas dataframe

Let's say 'members.xlsx' include columns corresponding to the members' data such as 'Country', 'Name', 'Job', 'Age', 'Hobby', 'Height', 'Weight', etc. I was able to figure out how to extract 'Name' ...
Karl's user avatar
  • 13
0 votes
1 answer
539 views

How to conditionally change pandas DataFrame values into f-strings?

I have a pandas DataFrame whose values I want to conditionally change into strings without looping over every value. Example input: In [1]: df = pd.DataFrame(data = [[1,2], [4,5]], columns = ['a', 'b']...
Haukur Björnsson's user avatar
0 votes
1 answer
2k views

function argument as an input for f-string to change variables

def cleaning(input): name = str(input) read_file = pd.read_csv('#f"{name}".csv') print(read_file) cleaning(InputKeyword) My function must take an input keyword, and this will ...
user avatar
1 vote
3 answers
1k views

Is there a way to incorporate f strings in pandas loc output

I'm trying to set up a script which will generate comments for student reports. To set up a general template, I'm using a marks table which has their percentage scores. I'm having trouble using an f ...
Liam Graneri's user avatar
0 votes
6 answers
497 views

f-strings with variable number of parameters?

I need to create messages of the kind Hi John, it's time to eat quantity_1 of food1, quantity_2 of food_2 ..., qunatity_n of food_n. For that I get pandas dataframes, that update every once in a while....
NeStack's user avatar
  • 2,022
-3 votes
1 answer
140 views

Moving Averages In pandas with f-string

How could i calculate a rolling average with f-stringed columns? Normally it's: df.columns=['x','y'] rollingaverage = df.y.rolling(window=6).mean() How do I do implement this given I use f-string? ...
arv's user avatar
  • 398
2 votes
1 answer
3k views

For loop with f-string with pandas dataframe

I need to try create two loops (must be separate): LOOP 1) for each fruit: keep rows if that fruit is True remove rows with duplicate dates (either row can be deleted) save the result of the above as ...
arv's user avatar
  • 398
0 votes
1 answer
56 views

when converting XML to SEVERAL dataframes, how to name these dfs in a dynamic way?

my code is on the bottom "parse_xml" function can transfer a xml file to a df, for example, "df=parse_XML("example.xml", lst_level2_tags)" works but as I want to save to several dfs so I want to have ...
neutralname's user avatar
20 votes
3 answers
17k views

Why doesn't f-string formatting work for Pandas?

Given a DataFrame with Product Id and Amount: df = pd.DataFrame([['504145', 12000.0], ['555933', 23010.5]], columns=['Product Id', 'Amount']) df Out[1]: ...
henrywongkk's user avatar
  • 1,918
2 votes
3 answers
3k views

How to create list of f-string (alike) based on pd.DataFrame values? [duplicate]

Problem How to create a list of strings with placeholders (i.e., "f-string"-like) based on values of a pandas DataFrame? Example Imagine I have following dataframe: import pandas as pd data = [ ...
ebosi's user avatar
  • 1,477