Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. id col1 col2
  2. 1 7 1.2
  3. 1 6 0.8
  4. 1 12 0.9
  5. 1 1 1.1
  6. 2 3 2.0
  7. 2 6 1.8
  8. 3 10 0.7
  9. 3 11 0.9
  10. 3 12 1.2
  11.  
  12. def myfunc(df, col1, col2):
  13.  
  14. df1 = col1
  15. df2 = df[df[col2] < 1][[col1]]
  16. var1 = df1.iloc[0]
  17. var2 = df2.iloc[0][0]
  18. # make calculations with var1 and var2
  19.  
  20. return 10 # dummy value for simplicity of an example
  21.  
  22.  
  23. df["new_col"] = df.groupby("id").agg(myfunc(...??))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement