ValueError: cannot reindex from a duplicate axis
The error "cannot reindex from a duplicate axis" usually generates when you concatenate, reindexing or resampling a DataFrame which the index has duplicate values . When you get this error, first you have to just check if there is any duplication in your DataFrame column names using the code:
df[df.index.duplicated()]
If DataFrame has duplicate index values , then remove the duplicated index:
df= df.loc[~df.index.duplicated(), :]
After you remove the duplicated columns from DataFrame, you should be able to run your DataFrame operations without any error.

Preserve
If you don't care about preserving the values of your DataFrame index , and you want them to be unique values, set ignore_index=True.
df = pd.concat(dfs,axis=0,ignore_index=True)
Overwrite
Alternatively, to overwrite your current DataFrame index with a new one:
df.index = new_index
or, use .reset_index:
df.reset_index(level=0, inplace=True)
Remove inplace=True if you want it to return the dataframe.
Prevent
In order to make sure your DataFrame cannot contain duplicate values in the index, you can set allows_duplicate_labels flag to False for preventing the assignment of duplicate values.
df.flags.allows_duplicate_labels = False
Related Topics
- ImportError: No module named pandas
- What is SettingWithCopyWarning?
- UnicodeDecodeError while reading CSV file
- How to fix CParserError: Error tokenizing data
- How to fix "Unnamed: 0" column in a pandas DataFrame
- ValueError: cannot convert float NaN to integer
- ValueError: Unknown label type: 'unknown'
- ValueError: Length of values does not match length of index
- ValueError: The truth value of an array with more than..