How to modify Dataframe column names in python

醉折花枝作酒筹
Release: 2021-04-27 09:30:04
forward
4403 people have browsed it

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
Copy after login
df = pd.DataFrame({'a':[1,2,3],'b':[1,2,3]})
Copy after login

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']
Copy after login

2. Only modify column name a to A

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

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!