liveBook · Manning

Plot.hist

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

A pandas plotting method that creates a histogram from numeric data.

plot.hist creates a histogram from numeric pandas data, making the distribution of a measured value visible at a glance. section 11.10

Inspecting tip percentages

Filter out nonpositive fares, calculate tip_percentage, keep values at or below 0.5, and plot the resulting Series: df.loc[lambda df_: df_['fare_amount'] > 0].assign(tip_percentage=lambda df_: df_['tip_amount'] / df_['fare_amount']).loc[lambda df_: df_['tip_percentage'] <= 0.5, 'tip_percentage'].plot.hist(). section 11.10

(
    df
    .loc[lambda df_: df_['fare_amount'] > 0]
    .assign(tip_percentage =
             lambda df_: df_['tip_amount'] / df_['fare_amount'])
    .loc[lambda df_: df_['tip_percentage'] <= 0.5,
         'tip_percentage']
    .plot.hist()
)

Open the complete method-chaining example for calculating and filtering tip percentages before calling plot.hist. section 11.10

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

How deep it goes
Demonstrates plot.hist within filtering and method chaining, but does not detail histogram configuration or implementation.
Examples
Uses New York taxi fares and tips to show the distribution of nonzero tip percentages up to fifty percent.
What it assumes
Assumes familiarity with pandas DataFrames, Series selection, boolean filtering, and method chaining.
What you can do after
Apply plot.hist to a prepared numeric Series and inspect its distribution visually.
How it connects
Connects plot.hist with pandas filtering, assign, lambda expressions, and method chaining.

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.