I've downloaded a Quandl dataset. I'm unable to infer or find the frequency of the data using infer_freq or freq. These two methods don't return anything. I don't understand what the problem is.
I'd like to see/print the frequency of the data, although I know it's 'daily'.
Below is the code I've used.
!pip install quandl
QUANDL_KEY = {my key}
quandl.ApiConfig.api_key = QUANDL_KEY
df = quandl.get(dataset='WIKI/SLB', start_date='2018-01-01', end_date='2020-12-17')
pd.infer_freq(df.index, warn=True) #returns nothing
#df.index.freq ## also returns nothing
#type(df.index) #pandas.core.indexes.datetimes.DatetimeIndex
For stock data, there is no data on the weekends and because of that pandas cannot infer a frequency. pd.infer_freq(df.index)
will return None if there's missing data. I guess you don't want to do df.asfreq('D')
because that will create None values for the missing data.
If you really want to infer the frequency from your Dataframe, you could just check the timedelta between consecutive rows (given you don't end up getting a timedelta of 3 days corresponding to a weekend)
td = df.index[1] - df.index[0]
freq = td.days # or explore td.components