0

I was going through a lot of questions here but nothing is working for me. I try to get an Datetime index for my Pandas Dataframe. tried resample, asfreq. The index is already a Datetime Object, but it keeps the NONE freq.

dfz = sale.loc[(sale.Open == 1) & (sale.Promo == 0) & (sale.Sales > 0), ["Sales", "Customers"]]
print(dfz.asfreq('M').index)
print(dfz.index)

Result is:

DatetimeIndex([], dtype='datetime64[ns]', name='Date', freq='M')
DatetimeIndex(['2015-07-20', '2015-07-20', '2015-07-20', '2015-07-20',
               '2015-07-20', '2015-07-20', '2015-07-20', '2015-07-20',
               '2015-07-20', '2015-07-20',
               ...
               '2013-01-06', '2013-01-06', '2013-01-06', '2013-01-06',
               '2013-01-06', '2013-01-06', '2013-01-06', '2013-01-06',
               '2013-01-06', '2013-01-06'],
              dtype='datetime64[ns]', name='Date', length=467463, freq=None)
            Sales  Customers

Why does it show me a freq in the result of the asfreq but when I call the index it is still NONE?

Nadine
  • 1
  • 1
    Can you show some of your data, and provide a [Minimal, Reproducible Example](https://stackoverflow.com/questions/tagged/pandas) in text form, not as a picture? I am not able to reproduce this error. – Bertil Johannes Ipsen Jun 17 '20 at 11:11
  • Sure I can provide the full csv as it is the Rossmann dataset from Kaggle. I took pandas to read it and set the date as index. https://www.kaggle.com/c/rossmann-store-sales/data?select=train.csv – Nadine Jun 18 '20 at 09:53
  • asfreq won't resample in-place; did you re-assign `dfz = dfz.asfreq('M')` before checking `dfz.index`? – FObersteiner Jun 18 '20 at 19:29

0 Answers0