HomeCourseModule 11 › Plotting directly from a DataFrame

Plotting directly from a DataFrame

Module 11 · Data Visualization7 min readBeginner

What you'll learn

  • Use df.plot() to chart a Series
  • Plot multiple columns at once
  • Pick the right kind (line/bar/area/hist)

The one-liner

df.set_index("date")["amount"].plot(figsize=(8, 4), title="Daily Revenue")

Multiple columns

df.set_index("date")[["amount", "forecast"]].plot()

Kinds

df["amount"].plot(kind="line")
df["amount"].plot(kind="hist", bins=30)
df["region"].value_counts().plot(kind="bar")
df["region"].value_counts().plot(kind="pie")    # use sparingly!
df.plot(kind="scatter", x="qty", y="amount")

Grouped bars from a pivot

pivot = df.pivot_table(index="region", columns="quarter",
                       values="amount", aggfunc="sum")
pivot.plot(kind="bar")

Stacked bars

pivot.plot(kind="bar", stacked=True)

Key takeaways

  • df.plot() is the quickest path from data to chart.
  • kind= picks the chart type.
  • For grouped/stacked bars, pivot first then plot.

Side-by-side bars

Pivot orders by region (rows) and quarter (columns). Plot the result as a grouped bar chart.

📹 Video walkthrough
A video walkthrough of this lesson will be embedded here. Until then, the written walkthrough above mirrors what the video will cover step-for-step.