如何在索引上绘制散点图作为x值

我在数据框中有以下数据:

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

索引值是日期,月,周和日。 据我了解,您无法在作为索引值的x上创建散点图:此处回答了类似的问题StackOverFlow link 我尝试过:

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

但我收到`KeyError:'Date'

此方法在链接中确实有效,但我不确定为什么它在这里不起作用。

此散点图确实适用于我的图,但是使用以下代码:

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

月份和日期均为索引值。我没有理由按日期绘制散点图,但出于学术原因,我只想知道

shuaishuailing9008 回答:如何在索引上绘制散点图作为x值

我不好的是,这个片段导致了问题:df = data.groupby(['month','day']).mean()

本文链接:https://www.f2er.com/3161308.html

大家都在问