How to rename columns in pandas

0 votes

I have a dataframe whose column names I want to edit the original column labels of Dataframe A

['A', 'B', 'C', 'D']

to

['w','x', 'y', 'z']
Aug 8, 2019 in Python by Shabnam
• 930 points
802 views

1 answer to this question.

0 votes

Hi, 

To rename columns in pandas, you can use rename method with axis='column' or axis=1 and refer the columns to be renamed.

df = df.rename(columns={'A':'w', 'B':'x', 'C':'y','D':'z'}, axis='cloumns')

OR

df = df.rename(columns={'A':'w', 'B':'x', 'C':'y','D':'z'}, axis=1)

answered Aug 9, 2019 by Taj
• 1,080 points

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

How to add multiple columns to pandas dataframe in one assignment?

Hello @kartik, You could use assign with a dict of ...READ MORE

answered Jun 15, 2020 in Python by Niroj
• 82,840 points
15,963 views
+1 vote
1 answer

How to change the order of DataFrame columns in pandas?

Hi@akhtar, You can rearrange a DataFrame object by ...READ MORE

answered Oct 20, 2020 in Python by MD
• 95,460 points
877 views
0 votes
1 answer

How to combine two columns of text in pandas dataframe?

If both columns are strings, you can ...READ MORE

answered Jan 5, 2021 in Python by Gitika
• 65,770 points
1,970 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,464 views
0 votes
1 answer
0 votes
1 answer

How to convert multiple columns to string in pandas dataframe?

Hi, To convert multiple columns to string, include a list of ...READ MORE

answered Jul 19, 2019 in Python by Taj
• 1,080 points
27,938 views
0 votes
1 answer

How to iterate over row in a Dataframe in Pandas?

Hi, You can use df.iterrows(), it yields both ...READ MORE

answered Jul 19, 2019 in Python by Taj
• 1,080 points
3,038 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP