df.plot(..., kind="line").
Goal
Draw this kind four ways.
df = pd.DataFrame({
"city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
"units": [21, 15, 15, 18, 12],
"shillings": [2100, 1500, 1480, 1750, 1190],
})
df.plot(x="city", y="units", kind="line")
plt.title("line")
plt.show()df = pd.DataFrame({
"month": ["Jan", "Feb", "Mar", "Apr"] * 2,
"mm": [48, 55, 92, 150, 22, 18, 40, 80],
"city": ["Nairobi"] * 4 + ["Mombasa"] * 4,
})
df[df["city"]=="Nairobi"].plot(x="month", y="mm", kind="line", marker="o")
plt.title("Nairobi rain")
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.head())
df.plot(x="city", y="shillings", kind="line")
plt.show()print("kind=line")