티스토리 뷰
Provides rolling window calculation
sum
mean
std
...
Example
import datetime
import pandas_datareader as web
start = datetime.datetime(2010,1,1)
end = datetime.datetime(2016,12,31)
#HyunDae
hd = web.DataReader('005380.KS', 'yahoo', start, end)
hd_close = hd['Close']
print(he_close.haed(5))
'''
Date
2010-01-04 119000.0
2010-01-05 110000.0
2010-01-06 111000.0
2010-01-07 106000.0
2010-01-08 106000.0
'''
print(hd_close.rolling(window=5).mean()[5])
#106900.0
print(he_close[:5].values.mean())
#106900.0
print(hd_close.rolling(window=5).mean())
'''
Date
2010-01-04 NaN
2010-01-05 NaN
2010-01-06 NaN
2010-01-07 NaN
2010-01-08 110400.0
2010-01-11 106900.0
...
'''
print(hd_close.rolling(window=5, center=True).mean())
#window size가 짝수 일 때 -> center : 올림하여 계산
'''
2010-01-04 NaN
2010-01-05 NaN
2010-01-06 110400.0
...
2016-12-27 144500.0
2016-12-28 NaN
2016-12-29 NaN
'''
#hd_close.rolling(window=12).std()
#hd_close.rolling(window=12).sum()
**reference**
http://ordo.tistory.com/67
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.rolling.html
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Machine Learning
- 터널링
- PYTHON
- VPN
- AWS
- style transfer
- TensorFlow
- deep learning
- IRR
- scipy
- filter
- Rolling
- numpy
- pandas
- FFT
- signal
- tacotron
- butterworth
- detrend
- database
- Computer science
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함