Resample - 改變時間序列的顆粒度

Python 的 pandas 套件內提供一個 resample 函式在處理這種事情,你可先參考:

https://machinelearningmastery.com/resample-interpolate-time-series-data-python/

知道它大概做什麼。然後你會發現,resample 的第一個參數有點陌生,它用來表示目標顆粒度的轉換 (the offset string or object representing target conversion): 這些顆粒度的表示法如下:

AliasDescription
Bbusiness day frequency
Ccustom business day frequency
Dcalendar day frequency
Wweekly frequency
Mmonth end frequency
SMsemi-month end frequency (15th and end of month)
BMbusiness month end frequency
CBMcustom business month end frequency
MSmonth start frequency
SMSsemi-month start frequency (1st and 15th)
BMSbusiness month start frequency
CBMScustom business month start frequency
Qquarter end frequency
BQbusiness quarter end frequency
QSquarter start frequency
BQSbusiness quarter start frequency
A, Yyear end frequency
BA, BYbusiness year end frequency
AS, YSyear start frequency
BAS, BYSbusiness year start frequency
BHbusiness hour frequency
Hhourly frequency
T, minminutely frequency
Ssecondly frequency
L, msmilliseconds
U, usmicroseconds
Nnanoseconds

又有

AliasDescription
W-SUNweekly frequency (Sundays). Same as ‘W’
W-MONweekly frequency (Mondays)
W-TUEweekly frequency (Tuesdays)
W-WEDweekly frequency (Wednesdays)
W-THUweekly frequency (Thursdays)
W-FRIweekly frequency (Fridays)
W-SATweekly frequency (Saturdays)
(B)Q(S)-DECquarterly frequency, year ends in December. Same as ‘Q’
(B)Q(S)-JANquarterly frequency, year ends in January
(B)Q(S)-FEBquarterly frequency, year ends in February
(B)Q(S)-MARquarterly frequency, year ends in March
(B)Q(S)-APRquarterly frequency, year ends in April
(B)Q(S)-MAYquarterly frequency, year ends in May
(B)Q(S)-JUNquarterly frequency, year ends in June
(B)Q(S)-JULquarterly frequency, year ends in July
(B)Q(S)-AUGquarterly frequency, year ends in August
(B)Q(S)-SEPquarterly frequency, year ends in September
(B)Q(S)-OCTquarterly frequency, year ends in October
(B)Q(S)-NOVquarterly frequency, year ends in November
(B)A(S)-DECannual frequency, anchored end of December. Same as ‘A’
(B)A(S)-JANannual frequency, anchored end of January
(B)A(S)-FEBannual frequency, anchored end of February
(B)A(S)-MARannual frequency, anchored end of March
(B)A(S)-APRannual frequency, anchored end of April
(B)A(S)-MAYannual frequency, anchored end of May
(B)A(S)-JUNannual frequency, anchored end of June
(B)A(S)-JULannual frequency, anchored end of July
(B)A(S)-AUGannual frequency, anchored end of August
(B)A(S)-SEPannual frequency, anchored end of September
(B)A(S)-OCTannual frequency, anchored end of October
(B)A(S)-NOVannual frequency, anchored end of November
例如:

resample("QS-JUN")

quarterly start frequency, year ends in June

留言

這個網誌中的熱門文章

標準差與 Wald 統計量

可能性比檢定(Likelihood ratio test)

Wold Decomposition Theorem