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










