

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Aggregation
incomplete
2: Grouping With Dictionaries
incomplete
3: Grouping in Pandas
incomplete
4: Category Type
incomplete
5: Grouping by Multiple Columns
incomplete
6: Multiple Aggregations
incomplete
7: Named Aggregations
incomplete
8: Custom Aggregations
incomplete
9: Pivot Tables
incomplete
10: Pivot Table Aggregations
incomplete
11: Star Schema
incomplete
12: Grain Validation
incomplete
13: Fixing Grain Violations
incomplete
14: Building a Data Model
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Now that we know how to aggregate data, let's talk about how to organize it. In a star schema, data is split into fact tables and dimension tables. Fact tables sit in the center, and dimension tables branch out like points of a star.
A fact table stores events: things that happened. Each row represents one event, like an order placed, a payment processed, or a page viewed.
Fact tables have 4 types of columns:
order_id (optional)customer_id, product_id, store_id)revenue, quantity, discount_amount)order_date, payment_time)orders = pd.DataFrame(
{
"order_id": ["ORD-7K2M", "ORD-9P4X", "ORD-3D8V", "ORD-6N1R"],
"customer_id": ["CUS-4821", "CUS-7316", "CUS-4821", "CUS-2059"],
"product_id": ["CHL-482", "TST-731", "CHL-482", "OVN-205"],
"order_date": ["2024-01-15", "2024-01-15", "2024-01-16", "2024-01-16"],
"quantity": [2, 1, 3, 1],
"revenue": [1598.00, 129.00, 2397.00, 349.00],
}
)
No customer names or product descriptions – just IDs, metrics, and timestamps. The descriptive details live elsewhere, in dimension tables.
Fact tables are where your metrics live. When someone asks, "What's total revenue by region?" the revenue comes from a fact table. You join it to dimension tables to get the region.
Keeping facts separate from descriptive data means: