Home  >  Article  >  Backend Development  >  How to modify Dataframe column names in python

How to modify Dataframe column names in python

醉折花枝作酒筹
醉折花枝作酒筹forward
2021-04-27 09:30:044406browse

This article will introduce you to two methods of modifying Dataframe column names in python. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to modify Dataframe column names in python

First create a new Dataframe

import pandas as pd
df = pd.DataFrame({'a':[1,2,3],'b':[1,2,3]})

as follows:
a b
0 1 1
1 2 2
2 3 31 , modify column name a and b to be A and B.

df.columns = ['A','B']

2. Only modify column name a to A

df.rename(columns={'a':'A'})

Related free learning recommendations: python video tutorial!

The above is the detailed content of How to modify Dataframe column names in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete