Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- id col1 col2
- 1 7 1.2
- 1 6 0.8
- 1 12 0.9
- 1 1 1.1
- 2 3 2.0
- 2 6 1.8
- 3 10 0.7
- 3 11 0.9
- 3 12 1.2
- def myfunc(df, col1, col2):
- df1 = col1
- df2 = df[df[col2] < 1][[col1]]
- var1 = df1.iloc[0]
- var2 = df2.iloc[0][0]
- # make calculations with var1 and var2
- return 10 # dummy value for simplicity of an example
- df["new_col"] = df.groupby("id").agg(myfunc(...??))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement