일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- GitHub
- Python
- mariadb
- install
- SciPy
- SPL
- ipad
- GT-S80
- 알고리즘
- imread
- DFS
- RNN
- javascript
- pip
- 삼성소프트웨어멤버십
- pandas
- Button
- pycharm
- Splunk
- Numpy
- Lotto
- mean
- Series
- CNN
- keras
- dataframe
- synology
- index
- E-P1
- LSTM
Archives
- Today
- Total
잠토의 잠망경
[python] 사분위 구하기 본문
사분위 구하기
목적: Data를 순서대로 늘어놓았을 때 아래부터 지정한 percent의 값에 맞는 값을 산출한다.
from scipy import stats
code
def sample_stats():
import numpy as np
from scipy import stats
fish_datas3 = np.asarray([1,2,3,4,5,6,7,8,9,10])
num = 25
print('{0}% = {1}'.format(num, stats.scoreatpercentile(fish_datas3, num)))
num = 75
print('{0}% = {1}'.format(num, stats.scoreatpercentile(fish_datas3, num)))
print('-'*10)
for i in range(13):
num = i*10
print('{0}% = {1}'.format(num, stats.scoreatpercentile(fish_datas3, num)))
결과 값
범위를 넘는 percent의 경우 아래와 같은 오류가 발생한다.
25% = 3.25
75% = 7.75
----------
0% = 1.0
10% = 1.9
20% = 2.8000000000000003
30% = 3.6999999999999997
40% = 4.6
50% = 5.5
60% = 6.3999999999999995
70% = 7.3
80% = 8.2
90% = 9.1
100% = 10.0
Traceback (most recent call last):
File "C:/Users/mellowlee/Project_Lotto/Sample006/sample_scipy.py", line 26, in <module>
sample_stats()
File "C:/Users/mellowlee/Project_Lotto/Sample006/sample_scipy.py", line 20, in sample_stats
print('{0}% = {1}'.format(num, stats.scoreatpercentile(fish_datas3, num)))
File "C:\Users\mellowlee\python_project\venv\lib\site-packages\scipy\stats\stats.py", line 1820, in scoreatpercentile
return _compute_qth_percentile(sorted_, per, interpolation_method, axis)
File "C:\Users\mellowlee\python_project\venv\lib\site-packages\scipy\stats\stats.py", line 1832, in _compute_qth_percentile
raise ValueError("percentile must be in the range [0, 100]")
ValueError: percentile must be in the range [0, 100]
Process finished with exit code 1
Comments