【发布时间】:2021-12-17 16:20:46
【问题描述】:
In [151]: df
Out[151]:
first bar baz
second one two one two
A 1 2 3 4
B 5 6 7 8
我的问题很简单:从这个df中,如何创建一个新的第三列,其中一列和两列的总和即得到:
In [151]: df
Out[151]:
first bar baz
second one two three one two three
A 1 2 3. 3. 4. 7.
B 5 6 11. 7. 8. 15.
谢谢。
【问题讨论】:
-
请以字典形式提供您的数据:
df.to_dict() -
{('bar', 'one'): {0: 1, 1: 5}, ('bar', 'two'): {0: 2, 1: 6}, ( 'baz', 'one'): {0: 3, 1: 7}, ('baz', 'two'): {0: 4, 1: 8}}
标签: python pandas multi-index