Hello, I'm a beginner who's having a hard time just after entering Python.
I posted a question a while ago, but I'm asking you again because I don't think you wrote the exact intention of the question.
What I'm curious about is to find a cumulative distribution function with some list.
For example,
list = [4, 6, 6, 6, 7, 8, 8, 8, 9, 10, 10, 10, 10, 10, 11, 12, 12, 12, 12, 12, 20, 20]
When you have these lists,
CDF = [1, 4, 4, 4, 5, 8, 8, 8, 9, 14, 14, 14, 14, 14, 15, 20, 20, 20, 20, 20, 22, 22]
We would like to obtain the cumulative distribution function values represented by the above shape and direct integer values.
Thank you for your help.
python
There's a method in Pandas called Rank.
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import pandas as pd
>>> l = [4, 6, 6, 6, 7, 8, 8, 8, 9, 10, 10, 10, 10, 10, 11, 12, 12, 12, 12, 12, 20, 20]
>>> s = pd.Series(l)
>>> s
0 4
1 6
2 6
3 6
4 7
5 8
6 8
7 8
8 9
9 10
10 10
11 10
12 10
13 10
14 11
15 12
16 12
17 12
18 12
19 12
20 20
21 20
dtype: int64
>>> s.rank()
0 1.0
1 3.0
2 3.0
3 3.0
4 5.0
5 7.0
6 7.0
7 7.0
8 9.0
9 12.0
10 12.0
11 12.0
12 12.0
13 12.0
14 15.0
15 18.0
16 18.0
17 18.0
18 18.0
19 18.0
20 21.5
21 21.5
dtype: float64
>>> s.rank(method='max')
0 1.0
1 4.0
2 4.0
3 4.0
4 5.0
5 8.0
6 8.0
7 8.0
8 9.0
9 14.0
10 14.0
11 14.0
12 14.0
13 14.0
14 15.0
15 20.0
16 20.0
17 20.0
18 20.0
19 20.0
20 22.0
21 22.0
dtype: float64
>>>
© 2024 OneMinuteCode. All rights reserved.