How to groupby multiple columns and aggregate diff on different columns?
问题 I am looking for help here on how to do this in Python / Panda: I am looking to take the original data (below) and find the daily difference of multiple cols (cnt_a and cnt_b) by a group with multiple cols (state, county and date). I've been trying it different ways, and I can't seem to get by the "check for duplicate" issue df.cnt_a = df.sort_values(['state','county','date']).groupby['state','county','date','cnt_a'].diff(-1) Tried splitting it out to fix one thing at a time: df1 = df.sort