Resample - 改變時間序列的顆粒度
Python 的 pandas 套件內提供一個 resample 函式在處理這種事情,你可先參考:
https://machinelearningmastery.com/resample-interpolate-time-series-data-python/
知道它大概做什麼。然後你會發現,resample 的第一個參數有點陌生,它用來表示目標顆粒度的轉換 (the offset string or object representing target conversion): 這些顆粒度的表示法如下:
https://machinelearningmastery.com/resample-interpolate-time-series-data-python/
知道它大概做什麼。然後你會發現,resample 的第一個參數有點陌生,它用來表示目標顆粒度的轉換 (the offset string or object representing target conversion): 這些顆粒度的表示法如下:
Alias | Description |
---|---|
B | business day frequency |
C | custom business day frequency |
D | calendar day frequency |
W | weekly frequency |
M | month end frequency |
SM | semi-month end frequency (15th and end of month) |
BM | business month end frequency |
CBM | custom business month end frequency |
MS | month start frequency |
SMS | semi-month start frequency (1st and 15th) |
BMS | business month start frequency |
CBMS | custom business month start frequency |
Q | quarter end frequency |
BQ | business quarter end frequency |
QS | quarter start frequency |
BQS | business quarter start frequency |
A, Y | year end frequency |
BA, BY | business year end frequency |
AS, YS | year start frequency |
BAS, BYS | business year start frequency |
BH | business hour frequency |
H | hourly frequency |
T, min | minutely frequency |
S | secondly frequency |
L, ms | milliseconds |
U, us | microseconds |
N | nanoseconds |
又有
Alias | Description |
---|---|
W-SUN | weekly frequency (Sundays). Same as ‘W’ |
W-MON | weekly frequency (Mondays) |
W-TUE | weekly frequency (Tuesdays) |
W-WED | weekly frequency (Wednesdays) |
W-THU | weekly frequency (Thursdays) |
W-FRI | weekly frequency (Fridays) |
W-SAT | weekly frequency (Saturdays) |
(B)Q(S)-DEC | quarterly frequency, year ends in December. Same as ‘Q’ |
(B)Q(S)-JAN | quarterly frequency, year ends in January |
(B)Q(S)-FEB | quarterly frequency, year ends in February |
(B)Q(S)-MAR | quarterly frequency, year ends in March |
(B)Q(S)-APR | quarterly frequency, year ends in April |
(B)Q(S)-MAY | quarterly frequency, year ends in May |
(B)Q(S)-JUN | quarterly frequency, year ends in June |
(B)Q(S)-JUL | quarterly frequency, year ends in July |
(B)Q(S)-AUG | quarterly frequency, year ends in August |
(B)Q(S)-SEP | quarterly frequency, year ends in September |
(B)Q(S)-OCT | quarterly frequency, year ends in October |
(B)Q(S)-NOV | quarterly frequency, year ends in November |
(B)A(S)-DEC | annual frequency, anchored end of December. Same as ‘A’ |
(B)A(S)-JAN | annual frequency, anchored end of January |
(B)A(S)-FEB | annual frequency, anchored end of February |
(B)A(S)-MAR | annual frequency, anchored end of March |
(B)A(S)-APR | annual frequency, anchored end of April |
(B)A(S)-MAY | annual frequency, anchored end of May |
(B)A(S)-JUN | annual frequency, anchored end of June |
(B)A(S)-JUL | annual frequency, anchored end of July |
(B)A(S)-AUG | annual frequency, anchored end of August |
(B)A(S)-SEP | annual frequency, anchored end of September |
(B)A(S)-OCT | annual frequency, anchored end of October |
(B)A(S)-NOV | annual frequency, anchored end of November |
例如:
resample("QS-JUN")
quarterly start frequency, year ends in June
留言
張貼留言