[英]I am getting an error when trying to plot a matplotlib scatter plot using for loop?
I am getting an error I cant seem to understand when im trying to plot a scatterplot below:当我尝试在下面绘制散点图时,我收到一个我似乎无法理解的错误:
plt.figure(figsize=(8,6))
for i in range(0,df.shape[0]):
plt.scatter(df['polarity'][i], df['subjectivity'][i], color = 'Blue' )
plt.title('Sentiment Analysis')
plt.xlabel('Polarity')
plt.ylabel('Subjectivity')
plt.show()
Where my polarity and subjectivity cols are number values我的极性和主观性 cols 是数值
I get我得到
KeyError:3
----> 3 plt.scatter(df['polarity'][i], df['subjectivity'][i], color = 'Blue' )
not sure what I am missing here, any help appreciated, thanks!不知道我在这里缺少什么,感谢任何帮助,谢谢!
df['polarity'][i]
extract item at index i
of the series df['polarity']
. df['polarity'][i]
在df['polarity']
系列的索引i
处提取项目。 The error says df['polarity']
does not have an index 3
, for example, df
can look like错误说
df['polarity']
没有索引3
,例如, df
看起来像
polarity
0 1
1 2
2 3
4 1
Why don't you try:你为什么不试试:
plt.scatter(df['polarity'], df['subjectivity'], color='b')
Or:或者:
df.plot.scatter(x='polarity', y='subjectivity')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.