John Doe
John Doe

Reputation: 677

Trouble in renaming column in a pandas DataFrame Python 3.7

I have the following columns and wish to change the 'Stores_num' to 'Stores_Num'

data.columns
Out[240]: 
Index(['INV_NUMBER', 'Store_num', 'Description', 'Price', 'Sold', 'Del',
       'Sales', 'Tot_Sls', 'Unit_Cost', 'Cost', 'Cost_Percent', 'Margin',
       'Profit', 'Date', 'Year', 'Month', 'Day'],
      dtype='object')

I use the following code:

data.rename(columns={'Stores_num':'Stores_Num'},inplace=True)

data.columns
Out[242]: 
Index(['INV_NUMBER', 'Store_num', 'Description', 'Price', 'Sold', 'Del',
       'Sales', 'Tot_Sls', 'Unit_Cost', 'Cost', 'Cost_Percent', 'Margin',
       'Profit', 'Date', 'Year', 'Month', 'Day'],
      dtype='object')

As you see the column name 'Stores_num' hasn't changed. What's wrong here.

Upvotes: 0

Views: 88

Answers (1)

Jai
Jai

Reputation: 849

There is nothing wrong in your code. It looks like you are using Jupyter Notebook for running the code. There is chance that previous data is stored in the cache, please restart and run all the cells. It should resolve the issue. Thanks

Upvotes: 1

Related Questions