散点图pandas x轴和y轴上的一个变量是数据帧索引

时间:2017-05-28 19:34:17

标签: pandas scatter-plot

我想在pandas中制作一个散点图,x轴是平均值,y轴应该是数据框的索引,但是我无法继续这是我的代码我遇到了很多错误。< / p>

y=list(range(len(df.index)))    
df.plot(kind='scatter', x='meandf', y  )    
error : SyntaxError: positional argument follows keyword argument

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

y=list(range(len(df.index)))

df.meandf.plot(x='meandf', y=y)

或者更简洁,因为您正在绘制Series

df.meandf.plot(y=y)

如果您需要维护kind = 'scatter',则需要传递数据帧:

df['y'] = y # create y column for the list you created
df.plot(x='a', y='y', kind='scatter', marker='.')
df.drop('y', axis=1, inplace=True)