Saltar al contenido

invalidindexerror: reindexing only valid with uniquely valued index objects

invalidindexerror: reindexing only valid with uniquely valued index objects

If you see the error invalidindexerror: reindexing only valid with uniquely valued index objects it means that you are trying to reindex a DataFrame using a non-unique index. For example:

df = pd.DataFrame({"A":[1,1,2,2], "B":[3,4,5,6]})

In the above DataFrame, the index is not unique because there are two rows with index values of 1. To fix this, you can specify a unique index when you reindex:

df.reindex(pd.unique(df.index))

Alternatively, you can drop the duplicated rows:

df.drop_duplicates(inplace=True)
QUIZÁ TE INTERESE:  i reincarnated as the crazed heir chapter 30

Deja una respuesta

Tu dirección de correo electrónico no será publicada.