Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: DataFrame index must be unique for orient='columns'

Tags:

python

pandas

I merged many dataframes into bigger one,

pd.concat(dfs, axis=0)

then I can not dump it into json

(Pdb) df.to_json() *** ValueError: DataFrame index must be unique for orient='columns'. 

How could I fix it ?

like image 977
user3675188 Avatar asked Mar 26 '15 05:03

user3675188


1 Answers

The error indicates that your dataframe index has non-unique (repeated) values. Since it appears you're not using the index, you could create a new one with:

df.reset_index(inplace=True) 

or

df.reset_index(drop=True, inplace=True) 

if you want to remove the previous index.

Check this link as well.

like image 131
davs2rt Avatar answered Oct 02 '22 13:10

davs2rt