python - 如何将列标题复制到熊猫中的其他列
问题描述
如何将一个列标题复制到同一 DataFrame 中的另一个列标题。并为python中的第二个标题添加后缀。
在我的数据中,我的标题是每月更改的月份。我想将该月自动复制到其他列。谢谢
解决方案
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
推荐阅读
- assembly - 索引寻址的语法(以及通常前导的逗号)
- angular9 - BehaviorSubject 下一个方法不更新另一个组件的更改
- ruby-on-rails - Rails 6,设计和主动存储
- fish - 鱼壳在管道中显示错误 - 新错误
- javascript - 将 CSS 应用于具有 NEXT Page 的数据表
- python - 按天采样的日期时间索引中的行数
- robotframework - Robotframework for loop 继续下一个测试
- regex - Need a regex expression 查找包含 a 和 e 的所有长度为 8 的单词
- javascript - 组件的状态来自其 prop,而该 prop 来自异步 API 调用
- javascript - 如何添加平滑过渡效果