Uber Ride Data Analysis
Given Uber ride/trip records:
- Find peak hours and weekdays
- Visualize trip volume over time
- Identify hotspots (if location data exists)
Analysis pipeline
Section titled “Analysis pipeline”flowchart LR A["Raw trips
(timestamps)"] --> B["Extract
(hour, weekday)"] B --> C["Count
(trips per hour/day)"] C --> D["Visualize
(demand curve)"] D --> E["Conclude
(peak hours/days)"]
Step 1: Load and parse timestamps
Section titled “Step 1: Load and parse timestamps”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
Section titled “Step 2: Extract time features”df["hour"] = df["timestamp"].dt.hour
df["weekday"] = df["timestamp"].dt.day_name()Step 3: Plot trips by hour
Section titled “Step 3: Plot trips by hour”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
Section titled “Step 4: Trend over dates”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
Section titled “Visualize it”Deliverable
Section titled “Deliverable”- Peak hours
- Peak weekdays
- Trend changes (seasonality/events)
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Extract the hour from a timestamp
Section titled “Exercise 1 – Extract the hour from a timestamp”Exercise 2 – Count trips per hour
Section titled “Exercise 2 – Count trips per hour”Exercise 3 – Weekday name from a date
Section titled “Exercise 3 – Weekday name from a date”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading