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

Time:08-09

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]}

CodePudding user response:

IIUC use:

d = df2.T.to_dict('list')
print (d)
{0: [500, 1], 1: [700, 4], 2: [1000, 5], 3: [700, 3]}
  • Related