3

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?

2
  • I think its df.groupby('property_name').hist() Commented Jan 12, 2017 at 19:14
  • So I've done that, how do I get it to work if there is more than two columns. I did it just now and it is pulling a histogram for each column with numerical values. (so it's producing multiple histograms for each property). How can I create just one histogram for each property based on duration Commented Jan 12, 2017 at 20:58

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

So I've done that, how do I get it to work if there is more than two columns. I did it just now and it is pulling a histogram for each column with numerical values. (so it's producing multiple histograms for each property). How can I create just one histogram for each property based on duration – Josh Dautel just now edit
2

Nevermind, got it!

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.