Reputation: 369
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, 1024.0], [0.0, 0.0, 1024.0, 1024.0]], ['Effusion', 'Emphysema', 'Infiltration', 'Pneumothorax']]
.
If you don't understand the data shape then please find the file shared in drive link
Each row having a single or multiple lists of lists and the first list pointing to the first disease which is mentioned in a string format in the second list and so on.
What is am Looking for:
I want to split this column to make new columns for each disease to make a data frame like this:
['Effusion'][[[0.0, 0.0, 1024.0, 1024.0]
for each disease mentioned.
OR want like this from the uploaded data
data frame like:
img_name
, class
, xmin = 0.0 , ymin= 0.0, xmax = 1024, ymax = 1024
If anyone is possible then iterates over all the rows and for all images and print, all Bounding Box coordinates on the image like below. OR
I want to make a data frame like this from the uploaded file link as you can see at the end:
img_name label xmin ymin xmax ymax
001 Effusion 0.0 0.0 1024 1024
001 Emphysema 0.0 0.0 1024 1024
001 Infiltration 0.0 0.0 1024 1024
001 Effusion 595.97 601.39 776.93 817.03
002 Mass 0.0 0.0 1024 1024
002 Cardiomagly 0.0 0.0 1024 1024
002 any disease 395.97 351.39 866.93 917.03
002 any disease 0.0 0.0 1024 1024
Here the above data frame style is change as I want to use explode function of pandas
data.
you can also use your expertise to just get those coordinated with the image name mentioned and print on the image. I am uploading a sample data frame here in this link: Dataframe
Thanks
Upvotes: 0
Views: 279
Reputation: 261860
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])]
Upvotes: 1