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 7 in Python by Shabnam
• 920 points
30 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 by Taj
• 1,040 points

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

How can I reformat value_counts() analysis in Pandas for large number of columns?

If I were you, I'd do it ...READ MORE

answered Apr 17, 2018 in Python by anonymous
2,505 views
0 votes
1 answer

How to replace values with None in Pandas data frame in Python?

Actually in later versions of pandas this ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 56,920 points
2,083 views
0 votes
1 answer

How to convert a Pandas GroupBy object to DataFrame in Python

g1 here is a DataFrame. It has a hierarchical index, ...READ MORE

answered Nov 12, 2018 in Python by Nymeria
• 3,520 points
8,250 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 346 views
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 18 in Python by Taj
• 1,040 points
436 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 18 in Python by Taj
• 1,040 points
57 views