Search code examples
pythonpandasvalueerror

I'm getting the following error message: ValueError: cannot reindex from a duplicate axis


Why am I getting this error message? My code:

my_df.loc[my_df['col1'] < my_df['col2'],'col3'] = my_df['col1'].

Basically what I'm trying to do is set col3 equal to col1 whenever col3 is less than col2. Thanks!


Solution

  • I solved this by resetting the index on the dataframes with reset_index(). The index got "messed up" due to a prior concat function.