1

I have the following data in dataframe :

High    Low Open    Close   Volume  Adj Close   year    pct_day
Date    month   week    day                             
1989-01-03  1   1   3   277.720001  273.809998  277.720001  275.309998  128500000   275.309998  1989    NaN
1989-01-04  1   1   4   279.750000  275.309998  275.309998  279.429993  149700000   279.429993  1989    0.014965
1989-01-05  1   1   5   281.510010  279.429993  279.429993  280.010010  174040000   280.010010  1989    0.002076
1989-01-06  1   1   6   282.059998  280.010010  280.010010  280.670013  161330000   280.670013  1989    0.002357
1989-01-09  1   2   9   281.890015  280.320007  280.670013  280.980011  163180000   280.980011  1989    0.001104
... ... ... ... ... ... ... ... ... ... ... ...
2006-12-22  12  51  22  1418.819946 1410.280029 1418.099976 1410.760010 1647590000  1410.760010 2006    -0.005316
2006-12-26  12  52  26  1417.910034 1410.449951 1410.750000 1416.900024 1310310000  1416.900024 2006    0.004352
2006-12-27  12  52  27  1427.719971 1416.630005 1416.630005 1426.839966 1667370000  1426.839966 2006    0.007015
2006-12-28  12  52  28  1427.260010 1422.050049 1426.770020 1424.729980 1508570000  1424.729980 2006    -0.001479
2006-12-29  12  52  29  1427.000000 1416.839966 1424.709961 1418.300049 1678200000  1418.300049 2006    -0.004513
4539 rows × 8 columns

The index value is Date, month, week and day. From what i understand you cannot create a scatter plot over x being an index value : a similar question was answered here StackOverFlow link I tried :

df.reset_index().plot(kind='scatter', x='Date', y='cumsum_pct_day')

but i get `KeyError: 'Date``

This method did work in the link but I am not sure why it is not working here.

This same scatterplot does work with i plot use the following code though:

df.reset_index().plot(kind='scatter', x='month', y='cumsum_pct_day')

Both month and Date are index values. There is no reason for me to plot scatter over date but for academic reasons i just want to know

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Slartibartfast
  • 1,058
  • 4
  • 26
  • 60

1 Answers1

2

My bad there was this snippit which was causing the problem: df = data.groupby(['month', 'day']).mean()

Slartibartfast
  • 1,058
  • 4
  • 26
  • 60