'Python Pandas ValueError: cannot reindex from a duplicate axis
This might be really simple but I'm trying to get a subset of values from a dataframe by selecting values where a column meets a specific value. So this:
test_df[test_df.ProductID == 18]
But I'm getting this error: *** ValueError: cannot reindex from a duplicate axis
Which is weird cause when I run this:
test_df.index.is_unique
I get true since my indices are unique. So what am I doing wrong?
I was able to get the exact same thing to work with another column:
test_df[test_df.AttributeID == 1111]
and that works exactly as expected.
Solved. I didn't check my dataframe close enough, there were duplicate columns called ProductID and that was what was causing the error.
Solution 1:[1]
If something is wrong with your index, you might reset the index with:
test_df.reset_index(level=0, inplace=True)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user18334962 |
