我安装了Pandas 17.0版本,但现在遇到一个奇怪的错误:
ValueError: keep must be either "first", "last" or False
当我尝试执行以下操作时:
ids=ids.drop_duplicates('ID')
之前的Pandas版本中,这总是有效的,代码没有改变。顺便提一下,ids
是包含整数列的数据帧...
以下是回溯信息:
Traceback (most recent call last):
File "<ipython-input-34-6e98a890591b>", line 1, in <module>
ids=ids.drop_duplicates('ID')
File "C:\Anaconda3\lib\site-packages\pandas\util\decorators.py",
line 89, in wrapper
return func(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\pandas\core\series.py", line
1164, in drop_duplicates
return super(Series, self).drop_duplicates(keep=keep, inplace=inplace)
File "C:\Anaconda3\lib\site-packages\pandas\util\decorators.py",
line 89, in wrapper
return func(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\pandas\core\base.py", line 576,
in drop_duplicates
duplicated = self.duplicated(keep=keep)
File "C:\Anaconda3\lib\site-packages\pandas\util\decorators.py",
line 89, in wrapper
return func(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\pandas\core\series.py", line
1169, in duplicated
return super(Series, self).duplicated(keep=keep)
File "C:\Anaconda3\lib\site-packages\pandas\util\decorators.py",
line 89, in wrapper
return func(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\pandas\core\base.py", line 603,
in duplicated
duplicated = lib.duplicated(keys, keep=keep)
File "pandas\lib.pyx", line 1383, in pandas.lib.duplicated
(pandas\lib.c:24490)
ValueError: keep must be either "first", "last" or False
注意keep=keep
吗?在Pandas 17.0中,drop_duplicates
的默认值为keep='first'
。所以如果我不指定,它不应该默认为这个吗?为什么我会在这里得到一个错误?是Pandas 17.0的错误吗?
ids
是一个Series
,那么type(ids)
显示什么? - EdChum