我有一个连续值Tone
。如何从数据框中创建频率表?
dataframe.Tone = [-0.9, -0.8, -0.6, -0.3, -0.2, 0, 0.1, 0.2, 0.4, 0.7, 1.2, 1.3, 1.4]`
resultDF
:
class interval | frequency
(-1.0) - (-0.6) | 3
(-0.5) - (-0.1) | 2
0 - 0.4 | 4
0.5 - 0.9 | 1
1 - 1.4 | 3
答案 0 :(得分:2)
IIUC使用cut
pd.cut(l,[-1,-0.6,-0.1,0.4,0.9,1.4]).value_counts()
(-1.0, -0.6] 3
(-0.6, -0.1] 2
(-0.1, 0.4] 4
(0.4, 0.9] 1
(0.9, 1.4] 3
dtype: int64