1

I am getting a very weird indexing problem with pandas and the arch package. Please see below.

      2018-07-01 12:00:00  0.13140109854255924
0     2018-07-01 16:00:00             0.144556
1     2018-07-01 20:00:00             0.158099
2     2018-07-02 00:00:00             0.171786
3     2018-07-02 04:00:00             0.185339
4     2018-07-02 08:00:00             0.198468
5     2018-07-02 12:00:00             2.513214

notice anything wrong. Its driving me doolaly cos I can't get rid of it. Now see:

df = df.iloc[1:,:]

print(df)

      2018-07-01 12:00:00  0.13140109854255924
2     2018-07-02 00:00:00             0.171786
3     2018-07-02 04:00:00             0.185339
4     2018-07-02 08:00:00             0.198468
5     2018-07-02 12:00:00             2.513214
6     2018-07-02 16:00:00             2.157013

now look at

df2 = pd.Series(range(100))

print(df2)

0      0
1      1
2      2
3      3
4      4
5      5

df3 = df.loc[df2.index,:]

print(df3)

    2018-07-01 12:00:00  0.13140109854255924
0                   NaN                  NaN
1                   NaN                  NaN
2   2018-07-02 00:00:00             0.171786
3   2018-07-02 04:00:00             0.185339
4   2018-07-02 08:00:00             0.198468
5   2018-07-02 12:00:00             2.513214
6   2018-07-02 16:00:00             2.157013

I think it may be the package. Because df2 above looks ok. So here is my code for generating df.

from arch import arch_model

am = arch_model(series)
res = am.fit(update_freq=5,disp='off')


sres = res.resid/res.conditional_volatility
vola = res.conditional_volatility
print(sres)
sres.to_csv(filename,index=True)
bharatk
  • 4,202
  • 5
  • 16
  • 30
mikey1
  • 31
  • 1
  • 4
  • Are you reading data from a CSV file? It seems the first line in your dataset was interpreted as column titles. Also please provide more useful descriptions besides "notice anything weird?" and "it drives me doolaly". Useful descriptions are "I expected X but got Y" – Nils Werner Jul 22 '19 at 13:00
  • Ok. I apologise for the dramatic language. But I think my post was descriptive enough. And yes I am reading from csv. – mikey1 Jul 22 '19 at 13:07
  • 2
    What is the output of `df.columns`? – Brendan Jul 22 '19 at 13:09
  • Hi, I found this work around. https://stackoverflow.com/questions/31328861/python-pandas-replacing-header-with-top-row, not sure its a complete solution but it works. – mikey1 Jul 22 '19 at 15:31

0 Answers0