I have the following data:
[4.1, 4.1, 4.1, 4.2, 4.3, 4.3, 4.4, 4.5, 4.6, 4.6, 4.8, 4.9, 5.1, 5.1, 5.2, 5.2, 5.3, 5.3, 5.3, 5.4, 5.4, 5.5, 5.6, 5.6, 5.6, 5.7, 5.8, 5.9, 6.2, 6.2, 6.2, 6.3, 6.4, 6.4, 6.5, 6.6, 6.7, 6.7, 6.8, 6.8]
I need to build its count/frequency table like this based on the data above:
4.1 - 4.5: 8
4.6 - 5.0: 4
5.1 - 5.5: 10
5.6 - 6.0: 6
6.1 - 6.5: 7
6.6 - 7.0: 5
The closest I can get is the following result:
counts freqs
categories
[4.1, 4.6) 8 0.200
[4.6, 5.1) 4 0.100
[5.1, 5.6) 10 0.250
[5.6, 6.1) 6 0.150
[6.1, 6.6) 7 0.175
[6.6, 7.1) 5 0.125
Through this code:
sr = [4.1, 4.1, 4.1, 4.2, 4.3, 4.3, 4.4, 4.5, 4.6, 4.6, 4.8, 4.9, 5.1, 5.1, 5.2, 5.2, 5.3, 5.3, 5.3, 5.4, 5.4, 5.5, 5.6, 5.6, 5.6, 5.7, 5.8, 5.9, 6.2, 6.2, 6.2, 6.3, 6.4, 6.4, 6.5, 6.6, 6.7, 6.7, 6.8, 6.8]
ncut = pd.cut(sr, [4.1, 4.6, 5.1, 5.6, 6.1, 6.6, 7.1],right=False)
srpd = pd.DataFrame(ncut.describe())
I need to create a new column, which is the median of the "categories" value (e.g. for "[4.1, 4.6)", this contains the count / frequency of data from 4.1 to 4.5 (not including 4.6)), So I need to get (4.1 + 4.5) / 2, which is equal to 4.3.
Here are my questions:
1) How do I access the values under the "categories" index to use it for computation like above?
2) Is there a way to reflect the range in this way: 4.1 - 4.5, 4.6 to 5.0, etc..?
3) Is there an easier way to compute for mean, median, mode, etc for grouped data like these? or do I have to create my own functions for these in Python?
Thanks