Python Central HubSign in

Data Analytics with Python / Phase 10: Data Analytics Projects

Uber Ride Data Analysis

Analyze trip data - time patterns, pickup hotspots, and demand peaks.

Goal

Given Uber ride/trip records:

  • Find peak hours and weekdays
  • Visualize trip volume over time
  • Identify hotspots (if location data exists)

Analysis pipeline

diagram Uber demand analysis pipeline mermaid
From raw trip timestamps to peak-hour demand patterns.

Step 1: Load and parse timestamps

Python
import pandas as pd
 
df = pd.read_csv("data/uber.csv")
 
df["timestamp"] = pd.to_datetime(df["timestamp"], errors="coerce")
print(df.head())

Step 2: Extract time features

Python
df["hour"] = df["timestamp"].dt.hour
df["weekday"] = df["timestamp"].dt.day_name()

Step 3: Plot trips by hour

Python
import seaborn as sns
import matplotlib.pyplot as plt
 
plt.figure(figsize=(8, 4))
sns.countplot(data=df, x="hour")
plt.title("Trips by hour")
plt.tight_layout()
plt.show()

Step 4: Trend over dates

Python
import matplotlib.pyplot as plt
 
daily = df.dropna(subset=["timestamp"]).groupby(df["timestamp"].dt.date).size()
 
plt.figure(figsize=(10, 4))
plt.plot(daily.index, daily.values)
plt.title("Trips over time")
plt.xticks(rotation=20)
plt.tight_layout()
plt.show()

Visualize it

sketch Trips by hour of day p5.js
Tall bars around commute hours reveal the demand peaks.

Deliverable

  • Peak hours
  • Peak weekdays
  • Trend changes (seasonality/events)

Check your understanding

quizCheck yourself
  1. Which pandas feature extracts the hour from the timestamp column?

    Show answer

    A — df["timestamp"].dt.hour — The dt accessor works on datetime columns, after converting with pd.to_datetime.

  2. What does sns.countplot(data=df, x="hour") show?

    Show answer

    A — The number of trips in each hour of the day — It counts rows per hour, a frequency table of timestamps, which reveals peak hours.

  3. How are trips per calendar day computed?

    Show answer

    A — Group by timestamp.dt.date after dropping missing timestamps and count rows — It uses groupby(df["timestamp"].dt.date).size() on rows that have valid timestamps.

  4. What does dt.day_name() give you for the weekday analysis?

    Show answer

    A — Text names such as Monday for each timestamp — It converts each timestamp to a weekday name so you can compare peak weekdays.

🧪 Try It Yourself

Exercise 1 – Extract the hour from a timestamp

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Count trips per hour

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – Weekday name from a date

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did