I have this df
sample:
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
where "Name"
is an index and "Cords"
is index in second level, that is, multiindex DataFrame, but now I want to calculate the slope between de index x
and y
in order to get:
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
do I have to use df.xs
?, i dont know exactly how multiindex df work.
slope = (y2-y1)/(x2-x1)