import pandas as pd
import numpy as np
# 开始时间,周期,频率
rng = pd.date_range('2016-07-01', periods = 10, freq = '3D')
time=pd.Series(np.random.randn(20),
index=pd.date_range(dt.datetime(2016,1,1),periods=20))
print(time)
#截去2016-1-10 之前的
time.truncate(before='2016-1-10')
#截去2016-1-10 之后的
time.truncate(after='2016-1-10')
#索引与切片
print(time['2016-01-15'])
print(time['2016-01-15':'2016-01-20'])
#M 表示月
data=pd.date_range('2010-01-01','2011-01-01',freq='M')
#时间戳
t = pd.Timestamp('2016-07-10 10:15')
#时期区间
pd.Period('2016-01') #一月
#时间间隔
pd.Timedelta('1 day')
pd.Period('2016-01-01 10:10') + pd.Timedelta('1 day')
p1 = pd.period_range('2016-01-01 10:10', freq = '25H', periods = 10)
p2 = pd.period_range('2016-01-01 10:10', freq = '1D1H', periods = 10)
p2 = pd.period_range('2016-01-01 10:10', freq = '1D1H', periods = 10)
python time series
最新推荐文章于 2025-07-23 20:29:52 发布
