Selecting data with MultiIndex
📖 Scenario: You work in a store that sells fruits in different cities. You have sales data organized by city and fruit type. You want to find sales numbers for specific cities and fruits easily.
🎯 Goal: Build a pandas DataFrame with a MultiIndex for city and fruit. Then select sales data for a specific city and fruit using MultiIndex selection.
📋 What You'll Learn
Create a pandas DataFrame with a MultiIndex from tuples of city and fruit
Add a sales column with integer values
Create a variable for the city to select
Use .loc with the MultiIndex to select sales data for the chosen city
Print the selected sales data
💡 Why This Matters
🌍 Real World
Stores and companies often have sales data organized by multiple categories like city and product. MultiIndex helps manage and analyze such data efficiently.
💼 Career
Data analysts and scientists use MultiIndex DataFrames to handle complex datasets with multiple levels of grouping, making data selection and aggregation easier.
Progress0 / 4 steps