【发布时间】:2022-11-29 14:50:39
【问题描述】:
这是我正在使用的示例数据。我想要完成的是 1) 从 a 列减去 b 列和 2) 在 a 和 b 列前面创建 C 列。我想遍历并为 x、y 和 z 创建 C 列。
import pandas as pd
df = pd.DataFrame(data=[[100,200,400,500,111,222], [77,28,110,211,27,81], [11,22,33,11,22,33],[213,124,136,147,54,56]])
df.columns = pd.MultiIndex.from_product([['x', 'y', 'z'], list('ab')])
print (df)
以下是我想要得到的。
【问题讨论】:
-
通过文本或图像进行不期望的输出
-
我附上了图片
标签: python pandas dataframe pivot-table multi-index