Are there functions to retrieve the histogram counts of a Series in pandas?

后端 未结 3 1505
故里飘歌
故里飘歌 2021-01-01 14:16

There is a method to plot Series histograms, but is there a function to retrieve the histogram counts to do further calculations on top of it?

I ke

3条回答
  •  伪装坚强ぢ
    2021-01-01 14:43

    If you know the number of bins you want, you can use pandas' cut function, which is now accessible via value_counts. Using the same random example:

    s = pd.Series(np.random.randn(100))
    s.value_counts(bins=5)
    
    Out[55]: 
    (-0.512, 0.311]     40
    (0.311, 1.133]      25
    (-1.335, -0.512]    14
    (1.133, 1.956]      13
    (-2.161, -1.335]     8
    

提交回复
热议问题