Is there a way to retrieve the frequency of a time series in pandas?
rng = date_range('1/1/2011', periods=72, freq='H')
ts =pd.Series(np.random.randn(len(rng)), index=rng)
ts.frequency or ts.period are not methods available.
Thanks
Edit: Can we infer the frequency from time series that do not specify frequency?
import pandas.io.data as web
aapl = web.get_data_yahoo("AAPL")
<class 'pandas.tseries.index.DatetimeIndex'>
[2010-01-04 00:00:00, ..., 2013-12-19 00:00:00]
Length: 999, Freq: None, Timezone: None
Can we somehow can the aapl's frequency? As we know, it's business days.
For DatetimeIndex
>>> rng
<class 'pandas.tseries.index.DatetimeIndex'>
[2011-01-01 00:00:00, ..., 2011-01-03 23:00:00]
Length: 72, Freq: H, Timezone: None
>>> len(rng)
72
>>> rng.freq
<1 Hour>
>>> rng.freqstr
'H'
Similary for series indexed with this index
>>> ts.index.freq
<1 Hour>
To infer the frequency, just use the built-in fct 'infer_freq'
import pandas as pd
pd.infer_freq(ts.index)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With