Pandas manipulate columns

linkaiyi
Follow

rename columns

Use the df.rename() function and refer the columns to be renamed. Not all the columns have to be renamed:

df = df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'})
# Or rename the existing DataFrame (rather than creating a copy) 
df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'}, inplace=True)

save to csv without index

df.to_csv('your.csv', index=False)
Object has 0 attachments

Was this article helpful?

This article is viewed 16 times!

0 Comments

Leave a Comment

Support