2017-04-11 120 views
0

我有一個帶日期和calltime列的dateframe對象。python pandas:按範圍對數據框分組

正試圖建立一個基於第二列的直方圖。例如。 df.groupby('calltime').head(10).plot(kind='hist', y='calltime') 得到以下內容: enter image description here 事情是,我想獲得第一個酒吧的更多細節。例如。範圍本身0-2500是巨大的,所有的數據都隱藏在那裏......是否有可能以較小的範圍拆分組?例如。到50,或類似的東西?

UPD

date calltime 0 1491928756414930 4643 1 1491928756419607 166 2 1491928756419790 120 3 1491928756419927 142 4 1491928756420083 121 5 1491928756420217 109 6 1491928756420409 52 7 1491928756420476 105 8 1491928756420605 35 9 1491928756420654 120 10 1491928756420787 105 11 1491928756420907 93 12 1491928756421013 37 13 1491928756421062 112 14 1491928756421187 41 15 1491928756421240 122 16 1491928756421375 28 17 1491928756421416 158 18 1491928756421587 65 19 1491928756421667 108 20 1491928756421790 55 21 1491928756421858 145 22 1491928756422018 37 23 1491928756422068 63 24 1491928756422145 57 25 1491928756422214 43 26 1491928756422270 73 27 1491928756422357 90 28 1491928756422460 72 29 1491928756422546 77 ... ... ... 9845 1491928759997328 670 9846 1491928759998255 372 9848 1491928759999116 659 9849 1491928759999897 369 9850 1491928760000380 746 9851 1491928760001245 823 9852 1491928760002189 634 9853 1491928760002869 335 9856 1491928760003929 4162 9865 1491928760009368 531

+0

你可以使用df.hist()與箱參數 – Vaishali

+0

啊哈,它已經更好。但是,我也可以以某種方式將值添加到X比例尺,所以它可以看到酒吧的範圍? –

+0

如果沒有這些數據就很難想象,你可以發佈df.groupby('calltime')。head(10)的輸出嗎? – Vaishali

回答

1

使用bins

s = pd.Series(np.abs(np.random.randn(100)) ** 3 * 2000) 
s.hist(bins=20) 

enter image description here

或者您可以使用pd.cut製作自己的定製箱。

pd.cut(
    s, [-np.inf] + [100 * i for i in range(10)] + [np.inf] 
).value_counts(sort=False).plot.bar() 

enter image description here