0

So I have used the previous answer and question to my problems answer but in my case I am facing some error I don't know how to solve it.

Initially I have loaded a pandas data frame as df = pd.read_excel(fid_data), the content of this is checked in the next command df.info(), I get the following:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 118 entries, 0 to 117
Data columns (total 8 columns):
Date       118 non-null datetime64[ns]
MOEX       118 non-null float64
RTS        118 non-null float64
CAC40      118 non-null float64
DAX        118 non-null float64
FTSe100    118 non-null float64
nikkei     118 non-null float64
sp500      118 non-null float64
dtypes: datetime64[ns](1), float64(7)
memory usage: 7.5 KB

When I try to decompose moex = df.MOEX with this command res = sm.tsa.seasonal_decompose(moex, model='additive') I get the following error:

Traceback (most recent call last):
  File "Main.py", line 106, in <module>
    res = sm.tsa.seasonal_decompose(moex, model='additive')
  File "/home/arvaldez/anaconda3/lib/python3.6/site-packages/statsmodels/tsa/seasonal.py", line 68, in seasonal_decompose
    _pandas_wrapper, pfreq = _maybe_get_pandas_wrapper_freq(x)
  File "/home/arvaldez/anaconda3/lib/python3.6/site-packages/statsmodels/tsa/filters/_utils.py", line 46, in _maybe_get_pandas_wrapper_freq
    freq = index.inferred_freq
AttributeError: 'RangeIndex' object has no attribute 'inferred_freq'
Andres Valdez
  • 164
  • 17
  • 1
    looks like `seasonal_decompose` expects a time-indexed series, while your data is not. Maybe `df.set_index('Date', inplace=True)` would help. – Quang Hoang Apr 10 '19 at 18:54
  • @QuangHoang I should add that straight after defining the pandas object df????? – Andres Valdez Apr 10 '19 at 20:12
  • Yes, you can try that as well. There should be an option to set index by read_excel, maybe index_col, but I’m not totally sure. – Quang Hoang Apr 10 '19 at 20:14
  • @QuangHoang so far it didn't work good...... I tried to adapt this script https://towardsdatascience.com/an-end-to-end-project-on-time-series-analysis-and-forecasting-with-python-4835e6bf050b but I can not find the reason for my error and how to fix the error – Andres Valdez Apr 10 '19 at 21:19
  • @QuangHoang I have a new question. Thanks to your help months ago. I am studying a new data-frame. This is the DatetimeIndex: `DatetimeIndex: 8040 entries, 2017-03-20 07:00:00 to 2017-03-31 19:59:00`, and this is an arbitrary member of the dataframe `y 8040 non-null int64`, with the next property ``, when I check the frequency it returns 'None", how can I change this 'None' to Minutes....???? – Andres Valdez Aug 17 '19 at 17:18

1 Answers1

0

So many thanks to @QuangHoang, after loading the pandas df object you must define the temporal scale with df.set_index('Date', inplace=True), and the variable definitions now does not contains the Date array.

Before:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 118 entries, 0 to 117
Data columns (total 8 columns):
Date       118 non-null datetime64[ns]
MOEX       118 non-null float64
RTS        118 non-null float64
CAC40      118 non-null float64
DAX        118 non-null float64
FTSe100    118 non-null float64
nikkei     118 non-null float64
sp500      118 non-null float64
dtypes: datetime64[ns](1), float64(7)
memory usage: 7.5 KB

After:

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 118 entries, 2019-02-01 to 2009-05-01
Data columns (total 7 columns):
MOEX       118 non-null float64
RTS        118 non-null float64
CAC40      118 non-null float64
DAX        118 non-null float64
FTSe100    118 non-null float64
nikkei     118 non-null float64
sp500      118 non-null float64
dtypes: float64(7)
memory usage: 7.4 KB

Everything works as expected. Now I do not need to parse the Date array, since its inserted in each array...

Thanks again.-

Andres Valdez
  • 164
  • 17