我有一个s
带有重复索引的系列:
>>> s
STK_ID RPT_Date
600809 20061231 demo_str
20070331 demo_str
20070630 demo_str
20070930 demo_str
20071231 demo_str
20060331 demo_str
20060630 demo_str
20060930 demo_str
20061231 demo_str
20070331 demo_str
20070630 demo_str
Name: STK_Name, Length: 11
我只想通过以下方式保留唯一行和重复行的一份副本:
s[s.index.unique()]
Pandas 0.10.1.dev-f7f7e13
给出以下错误消息
>>> s[s.index.unique()]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "d:\Python27\lib\site-packages\pandas\core\series.py", line 515, in __getitem__
return self._get_with(key)
File "d:\Python27\lib\site-packages\pandas\core\series.py", line 558, in _get_with
return self.reindex(key)
File "d:\Python27\lib\site-packages\pandas\core\series.py", line 2361, in reindex
level=level, limit=limit)
File "d:\Python27\lib\site-packages\pandas\core\index.py", line 2063, in reindex
limit=limit)
File "d:\Python27\lib\site-packages\pandas\core\index.py", line 2021, in get_indexer
raise Exception('Reindexing only valid with uniquely valued Index '
Exception: Reindexing only valid with uniquely valued Index objects
>>>
那么如何以有效的方式删除额外的重复行,保留唯一行和重复行的一个副本?(最好在一行中)