当前位置:   article > 正文

pandas报错:cannot reindex from a duplicate axis

cannot reindex from a duplicate axis

Series或DataFrame存在重复索引时,使用reindex()函数会抛出上述错误:

  1. a = pd.Series([1,2,3,4,5,6],index=['a','b','c','d','e','a'])
  2. print(a)

        a    1
        b    2
        c    3
        d    4
        e    5
        a    6

a.reindex(['b','c','e','b'])

报错:

  1. Traceback (most recent call last):
  2. File "<stdin>", line 1, in <module>
  3. File "C:\Python\lib\site-packages\pandas\core\series.py", line 3325, in reindex
  4. return super(Series, self).reindex(index=index, **kwargs)
  5. File "C:\Python\lib\site-packages\pandas\core\generic.py", line 3689, in reindex
  6. fill_value, copy).__finalize__(self)
  7. File "C:\Python\lib\site-packages\pandas\core\generic.py", line 3707
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/926719
推荐阅读
相关标签
  

闽ICP备14008679号