【发布时间】:2019-05-09 10:53:01
【问题描述】:
我有以下带有两个标头的数据框。我需要用我的第二个标题(工业数据集)的字符串值创建一个新列
Region Industrial production
Italia 5669
Nord-ovest 1046
Piemonte 447
我的最终输出需要是:
Industrial production Region Industrial production
Industrial production Italia 5669
Industrial production Nord-ovest 1046
Industrial production Piemonte 447
【问题讨论】:
-
它会说“工业生产”而不是别的?只需输出“工业生产”作为列的值。你已经知道该怎么做了。
-
您需要重命名工业生产列之一
-
或
df.insert(0, 'Type', 'Industrial Production', allow_duplicates=True)如果不是索引。 -
作为评论:我正在上传多个具有奇怪数据组织的文件 - 主要识别信息之一 [工业生产] 在第二个标题中,而不是单独的列。其他文件不会有“工业生产,而是其他识别信息,例如人口或 GDP。这就是为什么我不能简单地重命名它。
标签: python string pandas header rename