如何在索引相同的情况下向熊猫数据框添加列

时间:2018-12-21 09:10:37

标签: python pandas

如何在数据框中添加一列,其中相同索引的值是重复的

数据框:

Electricity and heat               [1,0,0]
Electricity and heat               [0,1,0]
Electricity and heat               [0,1,1]
Electricity and heat               [1,0,1]
Industry                           [1,0,0]
Industry                           [0,1,0]
Industry                           [1,0,1]
Energy                             [1,0,0]
Energy                             [1,1,1]
Agriculture                        [1,0,0]
Industrial Processes               [1,0,0]
Other Fuel Combustion              [1,0,0]

我要添加的列:

Electricity and heat               13
Industry                            8
Energy                              5
Agriculture                         4
Industrial Processes                4
Other Fuel Combustion               4

我想要的样子:

Electricity and heat               [1,0,0]               13
Electricity and heat               [0,1,0]               13
Electricity and heat               [0,1,1]               13
Electricity and heat               [1,0,1]               13
Industry                           [1,0,0]               8
Industry                           [0,1,0]               8
Industry                           [1,0,1]               8
Energy                             [1,0,0]               5
Energy                             [1,1,1]               5
Agriculture                        [1,0,0]               4
Industrial Processes               [1,0,0]               4
Other Fuel Combustion              [1,0,0]               4

0 个答案:

没有答案
相关问题