Issue
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.
Solution
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>
Answered By - alko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.