本文转自知乎博文Zhuang Tommy Pandas 3:如何修改columns的名称 - 知乎 (zhihu.com)
@Zhuang Tommy
col_names = ["City","Colors_Reported","Shape_Reported","State","Time"]
ufo = pd.read_csv(r"ufo.csv", header = 0, names = col_names)
col_names = ["City","Colors_Reported","Shape_Reported","State","Time"]
ufo = pd.read_csv(r"ufo.csv")
ufo.columns = col_names
ufo = pd.read_csv(r"ufo.csv")
ufo.rename(columns = {"Colors Reported" : "Colors_Reported",
"Shape Reported" : "Shape_Reported"}, inplace = True)
ufo = pd.read_csv(r"ufo.csv")
ufo.columns = ufo.columns.str.replace(" ","_")
关于更详细的pandas DataFrame教程,可参考@Ding Jiaxiong 的博文
【Pandas入门教程】如何选择DataFrame的子集_pandas 子集-CSDN博客