Reputation: 168
Suppose I have a dataframe that looks like this
I want to aggregate this so that I just have this
How would I do this with pandas?
Upvotes: 0
Views: 52
Reputation: 6483
Try with pd.DataFrame.groupby
, and then agg with last
and sum
df.groupby('Tract').agg({'Year':'last','a':'sum','b':'sum','c':'sum'})
Output:
Year a b c
Tract
1111 2016 5 5 5
Upvotes: 3