79279599

Date: 2024-12-13 21:19:34
Score: 1
Natty:
Report link

One method with a pivot table:

df2 = df[list['abde']].copy() # take only the 4 columns needed
df2['e'] = df2['e'].astype(int)  # transform True/False to 1/0
pt = df2.pivot_table(index=['a', 'b'], columns=['e'], values='d', aggfunc='min').fillna(0)
display(pt) 

pt

pt[1] has the values for the column f for a given ('a', 'b')

df['f_calc'] = df.apply(lambda row: pt[1].loc[row['a'], row['b']], axis=1)
display(df)

res

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: rehaqds