3

I am trying to create month frequency index for time series analysis The datevariable is a timestamp starts from 2018-10-18 10:50:10 till 2019-11-25 15:09:33. I am getting the error in subject line i tried removing the nulls but that did not help. New to python programming, any help

df=pd.read_excel("Source_Data.xlsx",index_col="activation date",parse_dates=True)

df.rename(
    columns={
        "activation date":"Date",
        "Estimate Volumes in HL (ABI)":"Volume"
    },
    inplace=True
)

dataset=df.filter(["Date","Volume"],axis=1)

dataset.index.freq="MS"
Biplab1985
  • 127
  • 2
  • 9
  • Welcome to StackOverflow. Good answers need good questions. Have a look at [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve). You can edit your questions to make it easier to get help. – run-out May 10 '20 at 17:54
  • trimmed my question for better understanding – Biplab1985 May 11 '20 at 17:30
  • Please try to provide data sample in a format that readers can copy and make a dataframe with. _____ Your last two lines don't look right. Not sure what you are filter, but that filter column will normally reduce the columns you have. It's more typical to use .loc[:, ['Date', 'Volume'] assuming Date is not in the index, which it likely is. ______ The last line doesn't work that way. I think what you are looking for is resample the docs are [here](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.resample.html) – run-out May 12 '20 at 00:17

1 Answers1

0

Solution:

dataset.index.asfreq('MS')

Your dataset probably has missing months. You have to fill up every instance of the chosen frequency using "asfreq". It will then automatically set the freq='MS'. You can also fix dataset.index.freq="MS" yourself but it is automatically done for you once you apply asfreq('MS').

Diablo
  • 426
  • 6
  • 10