R.K.
R.K.

Reputation: 13

How to calculate average number per day of the week?

I have a list of data with total number of orders and I would like to calculate the average number of orders per day of the week. For example, average number of order on Monday.

0    2018-01-01 00:00:00           3162
1    2018-01-02 00:00:00           1146
2    2018-01-03 00:00:00            396
3    2018-01-04 00:00:00            848
4    2018-01-05 00:00:00           1624
5    2018-01-06 00:00:00           3052
6    2018-01-07 00:00:00           3674
7    2018-01-08 00:00:00           1768
8    2018-01-09 00:00:00           1190
9    2018-01-10 00:00:00            382
10   2018-01-11 00:00:00           3170

Upvotes: 1

Views: 1003

Answers (1)

Nicko
Nicko

Reputation: 362

  1. Make sure your date column is in datetime format (looks like it already is)
  2. Add column to convert date to day of week
  3. Group by the day of week and take average
df['Date'] = pd.to_datetime(df['Date'])  # Step 1
df['DayofWeek'] =df['Date'].dt.day_name()  # Step 2
df.groupby(['DayofWeek']).mean()  # Step 3

Upvotes: 1

Related Questions