Time series:
import numpy as np
import pandas as pd
rng = pd.date_range('1/1/2019', periods=100, freq='S')
ts = pd.Series(np.random.randint(0, 600, len(rng)), index=rng)
ts.resample('5Min').sum()
Time zone representation:
rng = pd.date_range('4/6/2019 00:00', periods=5, freq='D')
ts = pd.Series(np.random.randn(len(rng)), rng)
ts
ts_utc = ts.tz_localize('UTC')
ts_utc
Converting to another time zone:
ts_utc.tz_convert('US/Eastern')
Converting between time span representations:
rng = pd.date_range('1/1/2019', periods=6, freq='M')
ts = pd.Series(np.random.randn(len(rng)), index=rng)
ts
ps = ts.to_period()
ps
ps.to_timestamp()
Converting between period and timestamp:
In the following example, we convert a quarterly frequency with year ending in June to 10am of
the end of the month following the quarter end:
prng = pd.period_range('2018', '2019Q4', freq='Q-JUN')
ts = pd.Series(np.random.randn(len(prng)), prng)
ts.index = (prng.asfreq('M', 'e') + 1).asfreq('H', 's') + 9
ts.head()