When a table wins

Tiny tables.

Tiny tables.

Goal

Run every block and look at the Plot panel.

print("city     mango  soda")
print("Nairobi     12     9")
print("Mombasa      7     8")
plt.bar(["Nairobi mango", "Nairobi soda", "Mombasa mango", "Mombasa soda"], [12, 9, 7, 8])
plt.xticks(rotation=20)
plt.title("Four bars for four numbers — a table is cleaner")
plt.show()
df = pd.DataFrame({
    "city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
    "units": [21, 15, 15, 18, 12],
    "shillings": [2100, 1500, 1480, 1750, 1190],
})
print(df.to_string(index=False))
df = pd.DataFrame({
    "city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
    "units": [21, 15, 15, 18, 12],
    "shillings": [2100, 1500, 1480, 1750, 1190],
})
plt.bar(df["city"], df["units"])
plt.title("A chart wins when there are more cities")
plt.show()
Pitfall

Always plt.show(). Paste the whole editor.