0

I'm trying to just get the sum of 'ride_value' by this groupby. How do I do that?

df.groupby(['start_lat_3', 'start_lng_3'])['ride_value'].agg(['sum'])

I'm trying to do this:

df['sum'] = df.groupby(['start_lat_3', 'start_lng_3'])['ride_value'].agg(['sum'])

But of course, that doesn't work because the right-hand side is a Pandas DataFrame.

I tried:

df.groupby(['start_lat_3', 'start_lng_3'])['ride_value'].agg(['sum'])[2]
df.groupby(['start_lat_3', 'start_lng_3'])['ride_value'].agg(['sum'])[['sum']]
df.groupby(['start_lat_3', 'start_lng_3'])['ride_value'].agg(['sum'])['sum']
0

1 Answer 1

1

If you want to bring back a full df input, transform

df['sum'] = df.groupby(['start_lat_3', 'start_lng_3'])['ride_value'].transform('sum')

If you want it summarised, agg

df.groupby(['start_lat_3', 'start_lng_3']).agg({'ride_value':'sum'})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.