Project 25: Channel Message Pivot
Data Analyst
Builds on these lessons
Current Task
Objective
.pivot_table() reshapes long data into a wide summary grid — one row per index value, one column per column value, aggregated into each cell.
Task: pivot a messages DataFrame into a channel x user grid of message counts, filling missing combinations with 0.
index.py
import pandas as pd
messages = pd.DataFrame({
'channel': ['general', 'general', 'random'],
'user': ['a', 'b', 'a'],
'count': [5, 3, 7]
})
pivot = messages.pivot_table(values='count', index='channel', columns='user', fill_value=0)
print(pivot)
* Hint: Correct characters turn green, incorrect ones turn red.
Live Preview
🖼️
Verify your code to see the preview