0

I'm trying to summarize my dataframe on bee data. It's separated by state and year. I'm trying to find the annual averages of each column to create a dataframe that is a summary for the entire US bee population by year. I was trying to use this method, but I'm not getting the results I want.

usa = bees.groupby(['year'])['numcol'].mean()

usa['yieldpercol'] = bees.groupby('year')['yieldpercol'].mean()

usa['totalprod'] = bees.groupby('year')['totalprod'].mean()

The data frame looks like this: Dataframe

Alex Hall
  • 34,833
  • 5
  • 57
  • 89
  • Welcome to stack overflow. _"Not getting the results I want"_ Please [edit] your question to include your current output and how it's different from what you expect to make a [mcve] so that we can better understand your question – G. Anderson Sep 27 '21 at 17:12
  • Please also see [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and include your sample data in the text of your question, not as a picture or link – G. Anderson Sep 27 '21 at 17:13
  • Try using this tool I wrote to improve your question: https://futurecoder.io/course/#question You can import pandas, just expect to wait a bit after clicking Run while it downloads. Start your code with a small example like `bees = pd.DataFrame({'year': [2001, ...], 'numcol': [1, ...]})` or something rather than a file so it's easy for everyone to run the example. – Alex Hall Sep 27 '21 at 17:42
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 05 '21 at 13:46

0 Answers0