Reputation: 628
I want to take the average property assessment value for each zipcode (without counting the zeros). So I would have an average value for 02126 and an average value for 02130. I would like to drop all rows with 0 in AV_LAND. What is the best way to go about that in a pandas dataframe? Thanks in advance!
ZIPCODE AV_LAND
0 02130 7900
1 02126 0
2 02126 20600
3 02126 520800
4 02126 20800
5 02127 0
Upvotes: 1
Views: 1891
Reputation: 294506
assuming df
is your dataframe
df.loc[df.AV_LAND != 0].groupby('ZIPCODE').mean()
df.loc[df.AV_LAND != 0].groupby('ZIPCODE').mean().reset_index()
Upvotes: 2