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.

3
  • 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. Commented Apr 7, 2019 at 20:52
  • so, if I use a list as a container, then I can get the names as string? Commented Apr 7, 2019 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. Commented Apr 8, 2019 at 1:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.