【发布时间】:2021-08-28 03:35:18
【问题描述】:
我有这个df 示例:
Name Cords A B C
Ob1 y 4.95 2.15 2.29
x 36.33 47.8 460.2
Ob2 y 1.22 2.34 2.57
x 36.33 47.8 460.2
其中"Name"是索引,"Cords"是二级索引,即多索引DataFrame,但现在我想计算de索引x和y之间的斜率,以便得到:
Name Cords A B C
Ob1 y 4.95 2.15 2.29
x 36.33 47.8 460.2
slope 0 -0.24 3.39
Ob2 y 1.22 2.34 2.57
x 36.33 47.8 460.2
slope 0 0.09 5.57e-4
我必须使用df.xs吗?我不知道multiindex df是如何工作的。
slope = (y2-y1)/(x2-x1)
【问题讨论】:
标签: python pandas dataframe indexing multi-level