Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index Max_Mass (kg/m) Max_Diameter (m)
- 1 10 1
- 2 20 2
- 3 30 3
- 200 5 4
- 201 60 3
- 202 20 2
- 300 90 1
- 301 3 1
- 302 10 1
- 400 100 1
- 401 10 1
- 402 10 1
- groups = output_df.groupby(pd.cut(output_df.index, range(0,len(output_df), 100)))
- groups.max()['Max Mass (kg/m)']
- (groups.max()['Max Mass (kg/m)']).getidx()
- Index Max_Mass (kg/m) Max_Diameter (m)
- 3 30 3
- 201 60 3
- 300 90 1
- 400 100 1
- # Initialise the grouper.
- grouper = df.Index // 100
- # Get list of indices corresponding to the max using `apply`.
- idx = df.groupby(grouper).apply(
- lambda x: x.set_index('Index')['Max_Mass (kg/m)'].idxmax())
- # Compute the max and update the other columns based on `idx` computed previously.
- v = df.groupby(grouper, as_index=False)['Max_Mass (kg/m)'].max()
- v['Index'] = idx.values
- v['Max_Diameter (m)'] = df.loc[df.Index.isin(v.Index), 'Max_Diameter (m)'].values
- print(v)
- Max_Mass (kg/m) Index Max_Diameter (m)
- 0 30 3 3
- 1 60 201 3
- 2 90 300 1
- 3 100 400 1
Add Comment
Please, Sign In to add comment