NumPy提供了datetime64數(shù)據(jù)類型,可以用來(lái)表示日期和時(shí)間數(shù)據(jù)。時(shí)間序列數(shù)據(jù)可以通過(guò)NumPy的datetime64數(shù)據(jù)類型進(jìn)行存儲(chǔ)、操作和計(jì)算。以下是一些NumPy處理時(shí)間序列數(shù)據(jù)的常用方法:
import numpy as np
dates = np.array(['2021-01-01', '2021-01-02', '2021-01-03'], dtype='datetime64')
print(dates)
dates = np.array(['2021-01-01', '2021-01-02', '2021-01-03'], dtype='datetime64')
diff = dates[1] - dates[0]
print(diff)
dates = np.array(['2021-01-01', '2021-01-02', '2021-01-03'], dtype='datetime64')
print(dates[0])
date = np.datetime64('2021-01-01')
print(date)
總的來(lái)說(shuō),NumPy提供了豐富的功能和方法來(lái)處理時(shí)間序列數(shù)據(jù),可以方便地進(jìn)行存儲(chǔ)、操作和計(jì)算。