Issue
I've imported data from a .csv. There is a column within the data referring to number of people. The number of people ranges from 1 - 100 for each different input. My goal is to only plot on a histogram the inputs where number of people is less than 50.
I know how to plot the histogram. df['people'].hist()
But, how do I specify the range of people? I've tried df[df['people']< 50].hist() but that did not work.
I know this should be easy but I just don't get it! This is using python and pandas.
Solution
I used some sample data and tried to plot the histogram with df['people'][df['people']<50].hist()
but df[df['people']<50].hist()
also seems to work for me.
df = pd.DataFrame(
[1,1,2,3,3,5,7,8,9,10,
10,11,11,13,13,15,16,17,18,18,
18,19,20,21,21,23,24,24,25,25,
25,25,26,26,26,27,27,27,27,27,
29,30,30,31,33,34,34,34,35,36,
36,37,37,38,38,39,40,41,41,42,
43,44,45,45,46,47,48,48,49,50,
51,52,53,54,55,55,56,57,58,60,
61,63,64,65,66,68,70,71,72,74,
75,77,81,83,84,87,89,90,90,91], columns=['people'])
df.head()
df['people'][df['people']<50].hist()
I have attached a screenshot of the histogram.
Answered By - Kabilan Mohanraj
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.