liveBook · Manning

Bar chart

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

A bar plot represents categorical values with rectangular bars whose lengths are proportional to the represented quantities.

A bar chart turns grouped categorical values into rectangular bars, making differences easier to see than a page of numerical output. In pandas, prepare the grouping, select the measure, sort when needed, and call plot.bar(). section 11.1 section 11.2

A practical bar-chart workflow is:

  • Group rows by the category or categories that should label the x-axis. section 11.10
  • Select one numeric Series or aggregate a selected set of columns. section 11.2 section 11.10
  • Sort the resulting Series before plotting when the question requires an ordered comparison. section 11.2
  • Use figsize when many categories make the default figure difficult to read. section 11.2
  • Use stacked=True to show how several numeric components combine within each category. section 11.9 section 11.10

Taxi payments by month and year

After concatenating four taxi data frames, group by pickup year and month, sum total_amount, and plot the resulting indexed Series. The index supplies the x-axis and the values supply the bar heights. Repeat the pattern with passenger_count.count() to chart ride counts. section 11.10 section 11.9

City comparisons

For the 1,000 largest U.S. cities, count city rows by state, sort the counts, and plot them. For Pennsylvania, filter rows, clean percentage strings, convert them to numbers, sort, and plot city growth. section 11.2

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

This compact chain shows the full pattern: group taxi records, aggregate total payments, and render a bar chart with a larger figure. section 11.10

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

How deep it goes
Explains grouping, column selection, sorting, figure sizing, and stacking, but defers broader chart customization.
Examples
Uses U.S. city counts and growth, NYC taxi payments and rides, fare components, passenger counts, and state earnings.
What it assumes
Assumes familiarity with pandas data frames, filtering, groupby, and aggregation while reinforcing index and returned-Series reasoning.
What you can do after
Apply it via pandas to build sorted, sized, grouped, and stacked categorical comparisons from prepared data.
How it connects
Connects pandas groupby, Series, DataFrame indexes, pie charts, scatter plots, histograms, and stacked bar charts.

Also explained in

Compare how 9 books explain bar chart →

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.