Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I solve 'UserWarning: DataFrame columns are not unique, some columns will be omitted'?

i have a dataframe of 2 columns. i tried converting it into a dictionary using df2.set_index('pay').T.to_dict('list').

As there are duplicated keys, some columns were omitted. Is there any way to resolve this issue or an alternative method?

pay score
500 1
700 4
1000 5
700 3

I would like to achieve this dictionary.

{'0': [500, 1], '1': [700, 4], '2': [1000, 5], '3' [700, 3]}

like image 605
kpop trash Avatar asked Oct 26 '25 11:10

kpop trash


1 Answers

IIUC use:

d = df2.T.to_dict('list')
print (d)
{0: [500, 1], 1: [700, 4], 2: [1000, 5], 3: [700, 3]}
like image 186
jezrael Avatar answered Oct 28 '25 01:10

jezrael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!