Python 的 pandas 套件內提供一個 resample 函式在處理這種事情,你可先參考: 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, m...