0

I have a continuous value Tone. How do I create a frequency table from the dataframe?

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

1 Answer 1

2

IIUC using 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
Sign up to request clarification or add additional context in comments.

9 Comments

how to automatically change the class interval range? without defining [-1,-0.6,-0.1,0.4,0.9,1.4]. range = 0.4
@Ruzannah the second param of cut can be an int which is the number of bins you want
@Ruzannah something like pd.cut(l,np.arange(-1,1.4+0.5,0.4)).value_counts()
how about float ?
@Ruzannah what you mean float ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.