0

I have a Pandas DataFrame which has a two columns, pageviews and type:

    pageviews   type
0   48.0        original
1   1.0         licensed
2   181.0       licensed
...

I'm trying to create a histogram each for original and licensed. Each histogram would (ideally) chart the number of occurrences in a given range for that particular type. So the x-axis would be a range of pageviews and the y-axis would be the number of pageviews that fall within that range.

Any recs on how to do this? I feel like it should be straightforward...

Thanks!

1
  • there are a few straight-forward ways of doing this. what have you tried and which documentation have you read? Commented Jun 19, 2017 at 15:17

1 Answer 1

4

Using your current dataframe: df.hist(by='type')

For example:

# Me recreating your dataframe
pageviews = np.random.randint(200, size=100)
types = np.random.choice(['original','licensed'], size=100)

df = pd.DataFrame({'pageviews': pageviews,'type':types})

# Code you need to create faceted histogram by type
df.hist(by='type')

pandas.DataFrame.hist documentation

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

2 Comments

If you can create the dataframe like pageviews = np.random.randint(200, size=100); types = np.random.choice(['original','licensed'], size=100); df = pd.DataFrame({'pageviews': pageviews,'type':types}) it would be more understandable.
Oh, good point. I'll make that edit. I assume the OP does not need my setup code, but that's still a good fix.

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.