I have a dataframe where I'd like to add a column with conditional sum of values based on criteria in 2 (possibly 3) different columns. I'm trying to use lambda function such as:
df['newColumn'] = df[['colA','colB']].apply(lambda x,y:
df.loc[df['colA']==x].loc[df['colB']==y]['Total Amount'].sum())
This approach doesn't work although when I test the .loc statement separately and use values in lieu of x and y I do get the correct sum. I would like to bring in another column to this if possible. The error Im getting is: "() missing 1 required positional argument: 'y'", 'occurred at index colA. Any help greatly appreciated,