我正在分析NaN值的熊猫DataFrame,以便相应地对其进行清理。事先我要计算相关列中的NaN条目数
def _clean_nan_values(df_data, l_columns):
for c in l_columns :
n_nan = len(df_data.loc[df_data[c].isnull()].index)
[...]
在极少数情况下,这会引发错误(以下是完整的错误日志)
ValueError: cannot label index with a null key
很遗憾,我没有导致错误的数据。 有人知道在这个相当简单的步骤中什么可能导致此错误吗?
使用python == 2.7.13
使用pandas == 0.23.3
完整错误日志:
File "analyze_data.py", line 403, in _clean_nan_values
n_nan = len(df_data.loc[df_data[c].isnull()].index)
File "lib/python2.7/site-packages/pandas/core/frame.py", line 2688, in __getitem__
return self._getitem_column(key)
File "lib/python2.7/site-packages/pandas/core/frame.py", line 2695, in _getitem_column
return self._get_item_cache(key)
File "lib/python2.7/site-packages/pandas/core/generic.py", line 2489, in _get_item_cache
values = self._data.get(item)
File "lib/python2.7/site-packages/pandas/core/internals.py", line 4124, in get
raise ValueError("cannot label index with a null key")
ValueError: cannot label index with a null key