0

How do I rename data frame file with a text variable containing the new name in Python?

df_new_name = 'df_with_new_name'
df_to_rename = pd.read_csv('C:\file.csv').
df_to_rename.rename(df_new_name)  #  doesn't work, so...
print(df_with_new_name)  #  would not be possible
  • Does this answer your question: https://www.delftstack.com/howto/python/python-dynamic-variable-name/ ? The suggestion to use a dictionary is likely better than the global method. – Chaos_Is_Harmony Sep 11 '21 at 04:40
  • User Chaos_Is_Harmony post a link which led me to the answer (https://www.delftstack.com/howto/python/python-string-to-variable-name/) but I don't know how to give him a credit. – Dragan Panic Sep 11 '21 at 05:45
  • Please add further details of your problem in the question and try to be more specific. You can post what you tried and the screenshot of the error you got so that the question becomes more clear and understandable to the audience. – hbstha123 Sep 11 '21 at 06:03

0 Answers0