0

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.

ALollz
  • 57,915
  • 7
  • 66
  • 89
Yun Tae Hwang
  • 1,249
  • 3
  • 18
  • 30
  • 2
    sounds like a case of mixing data and names. Use a container for the dataframes, such as a list or dict instead, and use that to access the dataframes if you really want to. – Paritosh Singh Apr 07 '19 at 20:52
  • so, if I use a list as a container, then I can get the names as string? – Yun Tae Hwang Apr 07 '19 at 21:26
  • After you do `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 do `new_name=data_by_year`, and `new_name` will 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. – hpaulj Apr 08 '19 at 01:43

0 Answers0