Histogram of one field wrt another in pandas python -
i trying plot histogram distribution of 1 column respect another. example, if dataframe columns ['count','age'], want plot total counts in each age group. suppose in
age: 0-10 -> total count 20
age: 10-20 -> total count 10
age: 20-30 -> ... etc
i tried groupby('age')
, plotting histogram didn't work.
thanks.
update
here of data
df.head() age count 0 65 2417.86 1 65 4173.50 2 65 3549.16 3 65 509.07 4 65 0.00
also, df.plot( x='age', y='count', kind='hist')
shows
ok,if understand correctly, want weighted histogram
import pylab plt import pandas pd np = pd.np df = pd.dataframe( {'age':np.random.normal( 50,10,300).astype(int), 'counts':1000*np.random.random(300)} ) # test data #df.head() # age counts #0 38 797.174450 #1 36 402.171434 #2 49 894.218420 #3 66 841.786623 #4 51 597.040259 df.hist('age',weights=df['counts'] ) plt.ylabel('counts') plt.show()
Comments
Post a Comment