Guest User

Untitled

a guest
Dec 10th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. Index Max_Mass (kg/m) Max_Diameter (m)
  2. 1 10 1
  3. 2 20 2
  4. 3 30 3
  5.  
  6. 200 5 4
  7. 201 60 3
  8. 202 20 2
  9.  
  10. 300 90 1
  11. 301 3 1
  12. 302 10 1
  13.  
  14. 400 100 1
  15. 401 10 1
  16. 402 10 1
  17.  
  18. groups = output_df.groupby(pd.cut(output_df.index, range(0,len(output_df), 100)))
  19.  
  20. groups.max()['Max Mass (kg/m)']
  21.  
  22. (groups.max()['Max Mass (kg/m)']).getidx()
  23.  
  24. Index Max_Mass (kg/m) Max_Diameter (m)
  25. 3 30 3
  26. 201 60 3
  27. 300 90 1
  28. 400 100 1
  29.  
  30. # Initialise the grouper.
  31. grouper = df.Index // 100
  32. # Get list of indices corresponding to the max using `apply`.
  33. idx = df.groupby(grouper).apply(
  34. lambda x: x.set_index('Index')['Max_Mass (kg/m)'].idxmax())
  35. # Compute the max and update the other columns based on `idx` computed previously.
  36. v = df.groupby(grouper, as_index=False)['Max_Mass (kg/m)'].max()
  37. v['Index'] = idx.values
  38. v['Max_Diameter (m)'] = df.loc[df.Index.isin(v.Index), 'Max_Diameter (m)'].values
  39.  
  40. print(v)
  41. Max_Mass (kg/m) Index Max_Diameter (m)
  42. 0 30 3 3
  43. 1 60 201 3
  44. 2 90 300 1
  45. 3 100 400 1
Add Comment
Please, Sign In to add comment