liveBook · Manning

Day_of_week attribute

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

The pandas datetime attribute that returns the weekday as an integer from Monday zero through Sunday six.

A datetime column can turn calendar dates into weekday groups without adding a permanent helper column. The pandas dt.day_of_week attribute returns Monday as 0 and Sunday as 6. section 10.14

Compare taxi tipping by weekday

With pickup timestamps and a tip_percentage column, group directly on df['tpep_pickup_datetime'].dt.day_of_week, calculate the mean, and sort descending. The analysis finds little variation: Tuesdays and Wednesdays lead, while Fridays and Saturdays trail. section 10.14

df.groupby(df['tpep_pickup_datetime'].dt.day_of_week
    )['tip_percentage'].mean().sort_values(ascending=False)

Shows the complete weekday grouping, mean aggregation, and descending sort. section 10.14

The same datetime-accessor pattern supports progressively broader questions:

  • Group by .dt.hour to compare tipping across hours. section 10.14
  • Group by .dt.month or set the timestamp as an index before resampling by day or month. section 10.14

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Defines Monday-to-Sunday integer encoding and demonstrates direct groupby aggregation, stopping short of weekday-name labeling.
Examples
Analyzes New York taxi tip percentages by weekday, hour, month, and resampled date.
What it assumes
Assumes parsed datetime values, the pandas dt accessor, and familiarity with groupby and mean.
What you can do after
Apply via pandas weekday grouping to compare metrics across calendar days.
How it connects
Connects pandas datetime accessors with groupby, aggregation, and resampling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.