NotImplementedError:回溯(最近一次调用最后一次):<;ipython-input-54-87754d21578b>;在<;模块>;
我知道很多人问过关于“未实现错误”的问题。然而,在我查看了现有的答案后,我仍然不明白如何在我的情况下解决它 我的目标是获得过去10年平均GDP排名前15位的国家NotImplementedError:回溯(最近一次调用最后一次):<;ipython-input-54-87754d21578b>;在<;模块>;,python,pandas,dataframe,Python,Pandas,Dataframe,我知道很多人问过关于“未实现错误”的问题。然而,在我查看了现有的答案后,我仍然不明白如何在我的情况下解决它 我的目标是获得过去10年平均GDP排名前15位的国家 Newdata3dataframe如下所示 创建了一个新列 Newdata3['avgGDP']=(Newdata3['2006']+Newdata3['2007']+Newdata3['2008']+Newdata3['2009']+Newdata3['2010']+Newdata3['2011']+Newdata3['2012']
Newdata3
dataframe如下所示
创建了一个新列
Newdata3['avgGDP']=(Newdata3['2006']+Newdata3['2007']+Newdata3['2008']+Newdata3['2009']+Newdata3['2010']+Newdata3['2011']+Newdata3['2012']+Newdata3['2013']+Newdata3['2014']+Newdata3['2015'])/10
按降序排序
Newdata3 = Newdata3.sort_values(by=['avgGDP'], ascending=False)
def answer_three():
ans2= ans.squeeze()
return ans2
raise NotImplementedError()
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-54-87754d21578b> in <module>
4 return ans2
5
----> 6 raise NotImplementedError()
NotImplementedError:
已将数据帧转换为系列
ans=Newdata3['avgGDP']
ans2=ans.squeak()
写下答案
Newdata3 = Newdata3.sort_values(by=['avgGDP'], ascending=False)
def answer_three():
ans2= ans.squeeze()
return ans2
raise NotImplementedError()
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-54-87754d21578b> in <module>
4 return ans2
5
----> 6 raise NotImplementedError()
NotImplementedError:
然后我收到错误
Newdata3 = Newdata3.sort_values(by=['avgGDP'], ascending=False)
def answer_three():
ans2= ans.squeeze()
return ans2
raise NotImplementedError()
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-54-87754d21578b> in <module>
4 return ans2
5
----> 6 raise NotImplementedError()
NotImplementedError:
您自己在代码中通过写下一行引发了错误
raise NotImplementedError()
在执行名为“answer_three”的函数后,raise NotImplementedError()
executed会引发错误
如果不想引发错误,请删除此行
调试代码时使用assert
关键字。assert关键字允许您测试代码匹配中的条件是否返回True,如果不是,程序将引发AssertionError
assert type(answer_three()) == pd.Series, "Q3: You should return a Series!"
在上面的一行中,它正在检查名为
answer\u three()
的函数的返回类型是否为pd.series
,然后返回true(不做任何事情)否则会引发一个断言错误看起来像是您自己无缘无故地使用引发NotImplementedError()
?@ShubhamPeriwal Hey,但是raise NotImplementedError()
是练习中给出的原始编码内容,我不应该删除它?如果是这种情况,那么您可能使用不正确。也许他们在某些条件下使用它。例如:如果xxx,则引发错误
。在你的例子中,它只是每次都会提高,但这是练习中给出的原始编码内容,我不应该删除它?基本上NotImplemented
是一个例外,当代码或代码中的功能没有完成时,开发人员会提出这个例外。所以,也许在你的练习中,代码是不完整的,应该由你来完成。因此,当您实现所需功能时,请将其删除。谢谢您。但后来我遇到了第二个错误,说“你应该返回一个系列!”但我想我已经转换成了一个“系列”?那是哪里?这似乎是您在问题中未提供的代码中的另一个问题..谢谢您的时间。我只是更新问题。你介意再看一次吗?
assert type(answer_three()) == pd.Series, "Q3: You should return a Series!"