有人可以在我的Python代码中解释以下错误吗?
-
16-10-2019 - |
题
我正在分析Python中的数据集,以实现严格的学习目的。在下面写的代码中,我遇到了一些错误,这些错误无法摆脱。首先是代码:
plt.plot(decade_mean.index, decade_mean.values, 'o-',color='r',lw=3,label = 'Decade Average')
plt.scatter(movieDF.year, movieDF.rating, color='k', alpha = 0.3, lw=2)
plt.xlabel('Year')
plt.ylabel('Rating')
remove_border()
我遇到以下错误:
1. TypeError: 'str' object is not callable
2. NameError: name 'remove_border' is not defined
同样,标签='十年平均值'没有出现在图中。
最让我感到困惑的是,在单独的代码段中的图(见下文)中,我没有得到上面的第一个错误,尽管 remove_border
仍然是一个问题。
plt.hist(movieDF.rating, bins = 5, color = 'blue', alpha = 0.3)
plt.xlabel('Rating')
对所有或某些错误的任何解释都将不胜感激。谢谢
在评论之后,我将发布数据和下面的跟踪:下面给出了venade_mean。
year
1970 8.925000
1980 8.650000
1990 8.615789
2000 8.378947
2010 8.233333
Name: rating, dtype: float64
追溯:
TypeError Traceback (most recent call last)
<ipython-input-361-a6efc7e46c45> in <module>()
1 plt.plot(decade_mean.index, decade_mean.values, 'o-',color='r',lw=3,label = 'Decade Average')
2 plt.scatter(movieDF.year, movieDF.rating, color='k', alpha = 0.3, lw=2)
----> 3 plt.xlabel('Year')
4 plt.ylabel('Rating')
5 remove_border()
TypeError: 'str' object is not callable
我解决了remove_border问题。这是我犯的一个愚蠢的错误。但是我无法弄清“ str”的问题。
解决方案
似乎 remove border
没有定义。您必须在使用之前定义功能。
我不知道字符串错误从何而来,我不清楚。如果您发布完整的追溯,它将更清楚。
最后您的标签没有显示,因为您必须调用该方法 plt.legend()
其他提示
在我看来 remove_border()
不被识别为函数。看看您尚未列出它属于的软件包,您自己实施了吗? python猜测 remove_border
是一个字符串,您正在尝试“称呼它” - 像对待功能一样对待它。第二个错误是在说同一件事,功能 remove_border
在Python可以找到它的任何地方都没有定义。