Python 数据帧上的键错误。plot.line:不在索引中

Python 数据帧上的键错误。plot.line:不在索引中,python,pandas,Python,Pandas,我有一个名为df2的数据帧,它有a、b、c、d列,并被索引 0,1,2,3,4,5,6,7,8,9 所以我写 df2.plot.line(x=df2.index, y='b') 我得到一个错误: keyerror: int64Index([0,1,2,3,4,5,6,7,8,9], dtype='int64') not in index 我怎样才能克服这个问题 顺便说一句,当我输入(df2.index)时,我会得到pandas.core.index.range.RangeIndex 另外,列

我有一个名为
df2
的数据帧,它有
a、b、c、d列,并被索引
0,1,2,3,4,5,6,7,8,9

所以我写

df2.plot.line(x=df2.index, y='b')
我得到一个错误:

keyerror: int64Index([0,1,2,3,4,5,6,7,8,9], dtype='int64') not in index
我怎样才能克服这个问题

顺便说一句,当我输入(
df2.index
)时,我会得到
pandas.core.index.range.RangeIndex


另外,列
b
有10个元素作为索引。

尝试放置
df2=df2.reset_index()
,然后
df2.plot.line(x=df2.index,y='b')
。如果它不起作用,请包含一些示例最小数据帧,以便我们可以处理您的数据并找到解决方案。请包含一个数据示例。默认情况下,索引用作x轴,以便您只需执行
df2.plot.line(y='b')