I have a program that runs completely through but unfortunately is returning duplicates because of the way the base data is structured. Results looks like this:
Date Amount Source Type
7/16/2019 10 A B
7/17/2019 10 A B
7/15/2019 10 A B
7/15/2019 10 B B
I'd like to return:
Date Amount Source Type
7/17/2019 10 A B
7/15/2019 10 B B
7/17/2019 is chosen because its the last date we received 10 from source A and Type B.
I've tried:
df.drop_duplicates(subset='a','b','date', keep="last")
but its not quite working. Is there a better way to do this?
This worked
df[df.Date.eq(df.groupby(['Source','Type'])['Date'].transform('max'))]