Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the name of a dataframe in python 3.6

How to change name of existing data frame to newname that stored in variable.

newName = 'rSK_' + dimName.replace(' ', '') # rSK_TradeFlow
df.rename(newName) # this is not working
like image 528
Learnings Avatar asked Nov 16 '25 20:11

Learnings


1 Answers

You actually have already achieved what you want when you assign the data to a new variable name.

Say for example you have a dataframe called df_original, if you assign it to a new variable called 'df_new' such as:

df_new = df_original

In this case, the data frame is NOT copied, it just gets a new name that refers to the original data saved in the memory.

If you run 'df_new is df_original' the output is 'True'. So these are just different names pointing to the same dataset saved in the memory.

like image 71
Muhammet Coskun Avatar answered Nov 18 '25 08:11

Muhammet Coskun