0

I have a dataframe like the following:

State Name County Name Value
Idaho Ada 20
Idaho Ada 50
Pennsylvania Adams 70
Colorado Adams 25
Pennsylvania Adams 21
Illinois Adams 45
Illinois Madison 45
Illinois Madison 75

Then average the rows with similar State and County name such that the dataframe becomes this:

State Name County Name Mean
Idaho Ada 12.5
Pennsylvania Adams 55.47
Colorado Adams 47.2
Illinois Adams 19.5
Illinois Madison 75.14

Any kind of help is appreciated.

1 Answers1

0

Try:

df.groupby(['State Name','County Name']).mean()
rhug123
  • 7,893
  • 1
  • 9
  • 24