I have a pandas DataFrame named 'data_by_month'
Here is a dummy data:
data = {'date' : ['1', '2','3'],
'value1' : ['a', 'b' ,'c'],
'value2' : ['12','24','4']}
data_by_month = pd.DataFrame(data)
Now, as I work with this DataFrame, because I have other DataFrames to use alternatively (data_by_week or data_by_year), I defined another name for this DataFrame and use the new name throughout the work process, so I can just change the name once instead of changing all the names redundantly:
new_name = data_by_month
However, I don't know how I can get the DataFrame name as a string, 'data_by_month' in this case, regardless of which DataFrame is given.
new_name=data_by_month, both variables refer to the same object. In Python an object does not have a name, so you can't change it. Later you could donew_name=data_by_year, andnew_namewill reference a different object (dataframe). Edit the script file if you don't like the names you used at various points; don't try to do anything fancy to make changes at runtime.