Interactive Lesson: Python Food Delivery

Python & Pandas for Analytics Engineers – Food Delivery Analytics

Python & Pandas: Food Delivery Analytics

Master data manipulation through real-world delivery data analysis

Progress: 0 / 8 exercises completed šŸ† Score: 0 points
šŸ““ FoodDeliveryAnalytics.ipynb Python 3.9 | Ready
Markdown

šŸ• Welcome to Food Delivery Analytics!

In this interactive notebook, you’ll analyze real-world food delivery data to uncover insights about restaurant performance, delivery times, and customer satisfaction.

šŸ“Š Dataset Overview:
• 10,000+ food delivery orders
• Restaurant ratings and cuisines
• Delivery times and distances
• Customer feedback and tips

Learning Objectives:

  • Master Python data structures (lists, dictionaries, tuples)
  • Use Pandas for data manipulation and analysis
  • Clean and transform messy data
  • Perform grouping and aggregations
  • Build a complete ETL pipeline
Code In [1]:
# Exercise 1: Python Basics – Working with Restaurant Data # Let’s start by creating basic data structures for our food delivery system # Create a list of popular cuisines cuisines = [“Italian”, “Chinese”, “Mexican”, “Indian”, “Thai”] # Create a dictionary for a restaurant restaurant = { “name”: “Pizza Paradise”, “cuisine”: “Italian”, “rating”: 4.5, “delivery_time”: 30, “is_open”: True } # Use f-strings to create a description description = f”{restaurant[‘name’]} serves {restaurant[‘cuisine’]} food with a {restaurant[‘rating’]}ā˜… rating” print(description) # Create a tuple for coordinates (immutable) restaurant_location = (37.7749, -122.4194) # San Francisco print(f”Location: {restaurant_location[0]}°N, {restaurant_location[1]}°W”)
Code In [2]: EXERCISE
Hints:
• Use cuisines.append("Japanese") to add items
• Dictionary format: {"key": "value", "key2": value2}
• Sets use curly braces: {"Zone1", "Zone2", "Zone3"}
Code In [3]:
# Exercise 2: Introduction to Pandas – Loading Delivery Data import pandas as pd import numpy as np # Create sample delivery data delivery_data = { ‘order_id’: [1001, 1002, 1003, 1004, 1005], ‘restaurant’: [‘Pizza Paradise’, ‘Sushi Supreme’, ‘Taco Town’, ‘Burger Barn’, ‘Pizza Paradise’], ‘cuisine’: [‘Italian’, ‘Japanese’, ‘Mexican’, ‘American’, ‘Italian’], ‘order_value’: [25.99, 45.50, 18.75, 22.00, 31.25], ‘delivery_time’: [28, 35, 22, 25, 32], ‘rating’: [5, 4, 5, 3, 4], ‘tip’: [5.00, 8.00, 3.00, 2.00, 6.00] } # Create DataFrame df = pd.DataFrame(delivery_data) # Display basic information print(“šŸ” Food Delivery Orders Dataset”) print(“=” * 40) print(df.head()) print(f”\nDataset shape: {df.shape}) print(f”Total orders: {len(df)})
Code In [4]: EXERCISE
Code In [5]:
# Exercise 4: Data Filtering & Selection # Expand our dataset np.random.seed(42) expanded_data = { ‘order_id’: range(2001, 2021), ‘restaurant’: np.random.choice([‘Pizza Paradise’, ‘Sushi Supreme’, ‘Taco Town’, ‘Burger Barn’, ‘Thai Terrace’], 20), ‘order_value’: np.random.uniform(15, 60, 20).round(2), ‘delivery_time’: np.random.randint(15, 45, 20), ‘rating’: np.random.choice([3, 4, 5], 20, p=[0.2, 0.3, 0.5]), ‘is_peak_hour’: np.random.choice([True, False], 20) } df_orders = pd.DataFrame(expanded_data) # Filter high-value orders high_value = df_orders[df_orders[‘order_value’] > 40] print(f”High-value orders (>$40): {len(high_value)}) print(high_value[[‘restaurant’, ‘order_value’]]) # Filter by multiple conditions fast_good = df_orders[ (df_orders[‘delivery_time’] < 25) & (df_orders[‘rating’] >= 4) ] print(f”\nFast & highly-rated deliveries: {len(fast_good)})
Code In [6]: CHALLENGE
Markdown

šŸŽÆ Knowledge Check Quiz

Test your understanding of Python and Pandas concepts!

Question 1: Which data structure would be best for storing unique customer IDs?

List
Set
Tuple
Dictionary

Question 2: What Pandas method would you use to find missing values?

.dropna()
.isna()
.fillna()
.notna()
Markdown

šŸŽ‰ Congratulations!

You’ve completed the Python & Pandas Food Delivery Analytics exercise!

Key Skills Practiced:
āœ… Python data structures (lists, dicts, tuples, sets)
āœ… Pandas DataFrames and Series
āœ… Data cleaning and transformation
āœ… Grouping and aggregations
āœ… Building ETL pipelines
āœ… Best practices for analytics engineering

Next Steps:

  • Practice with larger datasets
  • Explore advanced Pandas functions
  • Learn about data visualization with matplotlib/seaborn
  • Build automated reporting pipelines
  • Integrate with SQL databases