-1

I'm working on a jupyter notebook, and I would like to get the average 'pcnt_change' based on 'day_of_week'. How do I do this?

Data Frame - gamestop

  • Please include any relevant information [as text directly into your question](https://stackoverflow.com/editing-help), do not link or embed external images of source code or data. Images make it difficult to efficiently assist you as they cannot be copied and offer poor usability as they cannot be searched. See: [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/15497888) – Henry Ecker May 18 '21 at 01:16
  • Please include a _small_ subset of your data as a __copyable__ piece of code that can be used for testing as well as your expected output for the __provided__ data. See [MRE - Minimal, Reproducible, Example](https://stackoverflow.com/help/minimal-reproducible-example), and [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/15497888). – Henry Ecker May 18 '21 at 01:16

1 Answers1

0

A simple groupby call would do the trick here.

If df is the pandas dataframe:

df.groupby('day_of_week').mean() 

would return a dataframe with average of all numeric columns in the dataframe with day_of_week as index. If you want only certain column(s) to be returned, select only the needed columns on the groupby call (for e.g.,

df[['open_price', 'high_price', 'day_of_week']].groupby('day_of_week').mean()
Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
Anand A
  • 1
  • 2