I have a pandas dataframe which I grouped on column 'groupID'.
gb = df.groupby('groupID')
Each row is a has a x and y coordinate and a residual (distance from the line x=y). Now I want to find the gradient between 2 points(x,y) in a group where the residual is the biggest and the smallest. I know how to use gb['residual'].min() and max() but that does not give me the row.
How can I calculate this?
df[gb ['residual'].idxmin()]
I think you need find all indices from max and min value of column
residual
byDataFrameGroupBy.idxmax
andDataFrameGroupBy.idxmin
and then select byloc
: