1

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
dancemc15
  • 598
  • 2
  • 7
  • 21

1 Answers1

2

assuming df is your dataframe

df.loc[df.AV_LAND != 0].groupby('ZIPCODE').mean()

enter image description here

df.loc[df.AV_LAND != 0].groupby('ZIPCODE').mean().reset_index()

enter image description here

piRSquared
  • 285,575
  • 57
  • 475
  • 624