首页 > 解决方案 > 如何将列标题复制到熊猫中的其他列

问题描述

如何将一个列标题复制到同一 DataFrame 中的另一个列标题。并为python中的第二个标题添加后缀。
在我的数据中,我的标题是每月更改的月份。我想将该月自动复制到其他列。谢谢

标签: pythonpandasdataframe

解决方案


df.head()

   total  speeding  alcohol
0   18.8     7.332    5.640
1   18.1     7.421    4.525
2   18.6     6.510    5.208
3   22.4     4.032    5.824
4   12.0     4.200    3.360

添加新字段:

df["total_copy"] = df["total"]

   total  speeding  alcohol  total_copy
0   18.8     7.332    5.640        18.8
1   18.1     7.421    4.525        18.1
2   18.6     6.510    5.208        18.6
3   22.4     4.032    5.824        22.4
4   12.0     4.200    3.360        12.0

推荐阅读