import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
rng = pd.date_range('2016/07/01', periods=10, freq='3D')
print(rng)
TIMES的几种书写方式
time = pd.Series(np.random.randn(20), index=pd.date_range(dt.datetime(2016,1,1),periods=20))
print(time)
'''
2016-01-01 1.171836
2016-01-02 -1.270964
2016-01-03 -0.635355
2016-01-04 -0.695312
2016-01-05 -0.490697
2016-01-06 -1.047179
2016-01-07 0.895428
2016-01-08 -1.516199
2016-01-09 0.850112
2016-01-10 1.441586
2016-01-11 0.054532
2016-01-12 0.231320
2016-01-13 -1.818684
2016-01-14 0.663896
2016-01-15 2.241499
2016-01-16 -1.172098
2016-01-17 -0.135401
2016-01-18 -1.289502
2016-01-19 0.509668
2016-01-20 0.550763
Freq: D, dtype: float64
'''
time.truncate(before='2024-1-10')
1月10之前的都被过滤掉了
pd.Timestamp('2016-07-10')
# Timestamp('2016-07-10 00:00:00')
pd.Timestamp('2016-07-10 10')
# Timestamp('2016-07-10 10:00:00')
pd.Timestamp('2016-07-10 10:15')
# Timestamp('2016-07-10 10:15:00')
pd.Period('2016-01')
# Period('2016-01', 'M')
# TIME OFFSETS
pd.Timedelta('1 day')
# Timedelta('1 days 00:00:00')
pd.Period('2016-01-01 10:10') + pd.Timedelta('1 day')
# Period('2016-01-02 10:10', 'T')
pd.Timestamp('2016-01-01 10:10') + pd.Timedelta('1 day')
# Timestamp('2016-01-02 10:10:00')
pd.Timestamp('2016-01-01 10:10') + pd.Timedelta('15 ns')
# Timestamp('2016-01-01 10:10:00.000000015')
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)