Choosing a Chart
The shape of the question decides the shape of the picture.
Four questions, four charts
A quantity per category is a bar. A value over time is a line. A distribution is a histogram. A relationship between two measurements is a scatter. Most bad charts are one of these four answering a different question.
import pandas as pd
df = pd.DataFrame({"team": ["red", "blue"], "score": [90, 70]})
# A quantity per category: a bar chart of this table.
print(df.set_index("team")["score"].to_dict())
What the code looks like
pandas plots directly from a table. The plotting is one line; the work is the summary you feed it, which is why this unit grades the summary.
# df.plot(kind="bar", x="team", y="score")
# df.plot(kind="line", x="day", y="visits")
# df["score"].plot(kind="hist", bins=10)
print("the table you plot is the part that has to be right")
Exercise
Try It YourselfWrite chart_data(df) that returns the table behind a bar chart of mean score per team, as a dictionary of team to mean rounded to one decimal place.
Press Run to see output