熊猫-是否可以通过将drop()函数应用于isull()函数的结果来删除缺失值?

我目前正在阅读《数据科学概论》一书,其所有代码都是用python2编写的,但是我正在尝试使其在python3上运行 因此,当我尝试运行时:

edu.drop(edu['Value'].isnull(), axis=0)

它给出以下错误:

KeyError                                  Traceback (most recent call last)
<ipython-input-60-445dd51fcf75> in <module>
----> 1 eduDrop = edu.drop(edu['Value'].isnull(), axis=0)
      2 eduDrop.head()

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in drop(self, labels, axis, index, columns, level, inplace, errors)
   3995             level=level,
   3996             inplace=inplace,
-> 3997             errors=errors,
   3998         )
   3999 

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py in drop(self, labels, axis, index, columns, level, inplace, errors)
   3934         for axis, labels in axes.items():
   3935             if labels is not None:
-> 3936                 obj = obj._drop_axis(labels, axis, level=level, errors=errors)
   3937 
   3938         if inplace:

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py in _drop_axis(self, labels, axis, level, errors)
   3968                 new_axis = axis.drop(labels, level=level, errors=errors)
   3969             else:
-> 3970                 new_axis = axis.drop(labels, errors=errors)
   3971             result = self.reindex(**{axis_name: new_axis})
   3972 

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in drop(self, labels, errors)
   5016         if mask.any():
   5017             if errors != "ignore":
-> 5018                 raise KeyError(f"{labels[mask]} not found in axis")
   5019             indexer = indexer[~mask]
   5020         return self.delete(indexer)

KeyError: '[ True  True False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n  True  True False False False False False False False False False False\n  True  True False False False False False False False False False False\n  True False False False False False False False False False False False\n  True False False False False False False False False False False False\n  True False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False  True  True  True  True  True  True\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n  True False False False False False False False  True  True  True  True\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False  True False  True False False False\n  True False False False False False False False False False False False\n False False False False False False False False False False False False\n False False False False False False False False False False False False\n False] not found in axis'

那么,这里的问题是什么:当前版本的drop()不支持此功能吗?

评论