liveBook · Manning

Histogram

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

A chart that displays the distribution of numeric values by grouping them into intervals and showing each group's frequency.

A histogram summarizes the distribution of numeric values by showing how frequently values occur across ranges. It is useful when the question is about the shape of a whole population rather than one value per category—for example, how tipping percentages, temperatures, or program counts are spread. section 11.10 section 11.16

In pandas, select the numeric Series to plot after preparing the data. Clean invalid values before calculating a derived measure: taxi rides with fare_amount of zero or less are removed before tip_amount is divided by fare_amount, avoiding infinite percentages. Filter the result to the range being investigated, then call .plot.hist(). section 11.10

Tip percentages for taxi rides

Filter to positive fares, compute tip_percentage, retain values up to 50%, and plot that Series. The resulting distribution has a very large 0% bar; apart from it, values are roughly centered around 20%–25%. A method chain can express the same preparation with .loc, .assign, and lambdas. section 11.10

(
    fields_of_study_df
    .loc[fields_of_study_df['CREDDESC'] == 'Bachelors Degree']
    .groupby('INSTNM')['CIPDESC'].count()
    .plot.hist()
)

This pipeline filters rows to bachelor’s degrees, counts program descriptions for each institution, and plots the resulting per-institution counts as a histogram. section 13.3

A histogram can also visualize an aggregate you first derive. Count bachelor’s or graduate programs per institution with groupby, then plot the count Series to see how many institutions offer relatively few or many programs. Seaborn’s sns.displot provides another route for a numeric column, with hue for colored groups and row for separate plots per group. section 13.3 section 11.16

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

How deep it goes
Works through data cleaning, derived values, filtering, grouped counts, and pandas or Seaborn plotting without explaining histogram binning internals.
Examples
Uses New York taxi tip percentages, maximum temperatures across cities, and bachelor’s and graduate programs per institution.
What you can do after
Apply it via pandas or Seaborn to plot a prepared numeric Series or per-group count distribution.
How it connects
Connects histograms to pandas Series, filtering, method chaining, groupby, count, Seaborn, and boxplots.

Also explained in

Compare how 11 books explain histogram →

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.