liveBook · Manning

Plot.bar

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

A pandas plotting method that creates a bar plot from tabular or grouped data.

Use plot.bar to turn tabular or grouped pandas results into bars. A grouped result supplies the x-axis through its index, while its values determine bar heights. section 11.10

Compare monthly taxi revenue and rides

Group taxi records by pickup year and month, sum total_amount, and call .plot.bar(figsize=(10, 10)) to compare revenue. For ride counts, select passenger_count and use .count() before plotting. Extend the comparison with .plot.bar(stacked=True) after summing fare components such as fare_amount, tips, and tolls. section 11.10

(
    df
    .groupby([df['tpep_pickup_datetime'].dt.year,
              df['tpep_pickup_datetime'].dt.month])
    ['total_amount'].sum()
    .plot.bar(figsize=(10,10))
)

The executable pipeline shows grouping by datetime components, aggregating total_amount, and rendering the result as a sized bar plot. section 11.10

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Explains the index-to-x-axis and values-to-y-axis mapping, then demonstrates ordinary, counted, sized, and stacked plots.
Examples
Uses taxi revenue, monthly ride counts, fare components by month, and fare components by passenger count.
What it assumes
Assumes familiarity with pandas DataFrames, groupby, column selection, aggregation, and datetime components.
What you can do after
Builds grouped bar charts by aggregating pandas data and chaining plot.bar with sizing or stacking options.
How it connects
Connects pandas groupby, aggregation, DataFrame indexes, counts, and stacked bar charts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.