我有以下几栏,希望将'Stores_num'更改为'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')
我使用以下代码:
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')
如您所见,列名“ Stores_num”未更改。这是怎么了。
您的代码没有错。看起来您正在使用Jupyter Notebook运行代码。以前的数据有可能存储在缓存中,请重新启动并运行所有单元。它应该解决问题。谢谢