Reputation: 117
I'm importing a CSV file which has the following header(column names):
"Appendix","Name / Organization","Issuer","Algorithm"
I tried changing the "Appendix" column name into "Other Info" but it doesn't work.
df.rename(columns={'Appendix':'Other Info'},
inplace=True)
I get no error and when I print the dataframe again, it looks like the original one. (nothing has changed). I don't understand why. Can you give me an idea?
Thank you!
Upvotes: 0
Views: 4820
Reputation: 1102
make sure column name doesn't have any invisible characters line space and'\n'. The key u give in df.replace
function should match the column name.
try theese
df.rename(columns={'df.columns[0]':'Other Info'},
inplace=True)
or
df.columns=["Other info","Name / Organization","Issuer","Algorithm"]
Upvotes: 1
Reputation: 416
Some methods to sort this out:
Restart the kernel and run again.
If it doesn't help, assign a list of new column names
df.columns = ['Other Info' , 'Name / Organization' , 'Issuer' , 'Algorithm']
Create a new column Other Info
, copy all the data from Appendix
and drop your Appendix
column
Upvotes: 1