Josh Dautel
Josh Dautel

Reputation: 143

Pandas, Histogram Plotting With Subplots Based on Column Values

I have a panda data table that looks something like this:

Panda Table

And it goes on through over a ton of rows. There's something like 30 or 40 different properties that I want to look at individually.

I'm looking to create a histogram for each individual property based on duration. So a histogram for property A, property B, property C, and so on....

I know how to do it for all properties, as seen in my below code:

df['duration'].plot(kind='hist', sharex=False, use_index=False, bins=100)
plt.show()

This is the histogram of all properties

Any ideas on how I might go about this?

Upvotes: 3

Views: 4609

Answers (2)

Josh Dautel
Josh Dautel

Reputation: 143

Nevermind, got it!

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.hist.html

df.groupby('property_name').hist(column='duration')

Upvotes: 2

piRSquared
piRSquared

Reputation: 294218

consider the following dataframe df

df = pd.DataFrame(dict(duration=np.random.rand(1000),
                       property_name=np.random.choice(list('abc'), 1000)))

Then you can do

df.groupby('property_name').hist(figsize=(10,2))

enter image description here

Upvotes: 2

Related Questions