I plan to create a function and run the function with several data sets.
I would like to add a column with values for each record of the name of the data set, based on the name of the data frame passed as a parameter.
I have an example here that creates a column with values of the argument argument1
, rather than the parameter name string_i_want
.
Is there a way I could obtain the name of the variable passed as the parameter string_i_want
and asign that as the value in the 'scenario' column rather than argument1
?
import pandas as pd
string_i_want = pd.DataFrame([1, 2, 3, 4], columns=['column_name'])
def example(argument1):
argument1['squared'] = argument1['column_name'] ** 2
argument1['scenario'] = f'{argument1=}'.split('=')[0]
return argument1
example(string_i_want)
The returned data frame is:
The returned data frame I would instead like to build is: