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:
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.
how to solve cannot reindex from a duplicate axis


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)


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.


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