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
