Python 多索引数据帧数据提取
我有一个pandas数据框,其中第一行有多个条目,但第二行有重复列Python 多索引数据帧数据提取,python,python-3.x,pandas,Python,Python 3.x,Pandas,我有一个pandas数据框,其中第一行有多个条目,但第二行有重复列 A B. C Date High Low High Low. High Low 2000-07-03 19.796038 19.202157 9.261945 9
A B. C
Date High Low High Low. High Low
2000-07-03 19.796038 19.202157 9.261945 9.011265 19.261945 9.011265
2000-07-05 19.845534 18.845534 9.81945 8.011 29.81945 8.011
我想找出哪个A、B或C在日期的高低上有最大的区别
Desired output:
C
Date High Low Difference
2000-07-05 29.81945 8.011. 21.808
哪一个更好的透视表、分组、熔化?我们可以做堆栈,然后是idxmax
我们可以做堆栈,然后是idxmax
s=df.stack(level=0)
idx=(s['High']-s['Low']).idxmax()
df.loc[[idx[0]],[idx[1]]]
Out[268]:
C
High Low
Date
2000-07-05 29.81945 8.011