pandas datafram重命名列名称

方法一:

直接给column赋值

df.columns=["a", "b"], 所有的column全部重命名

example:

import pandas as pd
>>> df = pd.DataFrame({"aa":[1,2,3], "bb": [4,5,6]})
>>> df
   aa  bb
0   1   4
1   2   5
2   3   6
>>> df.columns=["a", "b"]  # rename all columns
>>> df
   a  b
0  1  4
1  2  5
2  3  6

方法二:

使用rename(),可以选择一部分进行重命名。

>>> df.rename(columns={"a":"a1"})  # rename column a to a1, keep b unchanged, inplace=True to do it inplace
   a1  b
0   1  4
1   2  5
2   3  6

df.rename(columns={'原列名' : '新列名'}, inplace=True)

原文地址:https://www.cnblogs.com/buxizhizhoum/p/8118026.html