唯一索引抛出:重新索引仅对具有唯一值的索引对象有效

hen*_*axe 10 python-3.x pandas

所以我有一个数据帧列表。当尝试附加它们时,我得到:

pandas.errors.InvalidIndexError: Reindexing only valid
with uniquely valued Index objects
Run Code Online (Sandbox Code Playgroud)

但是,我的索引是唯一的,例如:

dfList[0].index
Index(['5560654070'], dtype='object')

fList[1].index
Index(['5562221068'], dtype='object')
Run Code Online (Sandbox Code Playgroud)

append()、 或 时concat(),都会给出上述错误。

dfList[0].append(dfList[1])

"""
pandas.errors.InvalidIndexError: Reindexing only valid with uniquely valued Index objects
"""
Run Code Online (Sandbox Code Playgroud)

reset_index()也尝试过ignore_index=True,但似乎没有任何效果。

hen*_*axe 30

找到了错误的原因。作为一个熊猫菜鸟,我认为这个错误只与索引有关。然而问题是我在每个数据框中都有重复的列。

  • 如果这个答案有更多细节就好了。 (11认同)