Skip to content
Advertisement

Concat DataFrame Reindexing only valid with uniquely valued Index objects

I am trying to concat the following dataframes:

df1

JavaScript

and:

df2

JavaScript

With

JavaScript

But I get the follwing output:

JavaScript

I have removed additional columns and removed duplicates and NA where there could be a conflict – but I simply do not know what’s wrong.

Advertisement

Answer

pd.concat requires that the indices be unique. To remove rows with duplicate indices, use

JavaScript

JavaScript

Note there is also pd.join, which can join DataFrames based on their indices, and handle non-unique indices based on the how parameter. Rows with duplicate index are not removed.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement