Skip to content Skip to sidebar Skip to footer

How To Split Multiple Lists In A Column And Make New Dataframe And Map For Specific Value In Python?

I am working on a data frame containing multiple columns. One of the column having multiple lists like: [[[0.0, 0.0, 1024.0, 1024.0], [0.0, 0.0, 1024.0, 1024.0], [0.0, 0.0, 1024.0,

Solution 1:

It is difficult to give you a precise code to run without a minimal reproducible example, but assuming this input:

list_of_list = [[[0.0, 0.0, 1024.0, 1024.0],
                 [0.0, 0.0, 1024.0, 1024.0],
                 [0.0, 0.0, 1024.0, 1024.0],
                 [0.0, 0.0, 1024.0, 1024.0]],
                ['Effusion', 'Emphysema', 'Infiltration', 'Pneumothorax']
               ]

You can use zip to reshape your list:

list(zip(list_of_list[1], list_of_list[0]))

or

list(zip(*list_of_list[::-1]))

output:

[('Effusion', [0.0, 0.0, 1024.0, 1024.0]),
 ('Emphysema', [0.0, 0.0, 1024.0, 1024.0]),
 ('Infiltration', [0.0, 0.0, 1024.0, 1024.0]),
 ('Pneumothorax', [0.0, 0.0, 1024.0, 1024.0])]

Post a Comment for "How To Split Multiple Lists In A Column And Make New Dataframe And Map For Specific Value In Python?"