0

I have a dataframe where i have multiple images for a each label.

Example:

|   | Images                      |   Labels |
|---|-----------------------------|----------|
| 0 | ['a.jpg', 'b.jpg', 'c.jpg'] |   label1 |
| 1 | ['a.jpg', 'e.jpg', 'f.jpg'] |   label2 | 

Now what i was expecting is

|   | Images                      |   Labels |
|---|-----------------------------|----------|
| 0 | 'a.jpg'                     |   label1 |
| 1 | 'b.jpg'                     |   label1 | 
| 2 | 'c.jpg'                     |   label1 | 
| 3 | 'a.jpg'                     |   label1 | 
| 4 | 'e.jpg'                     |   label2 | 
| 5 | 'f.jpg'                     |   label2 | 

I have tried using split(',') and explode which is messing then and returning output like this ["['a.jpg'"," 'b.jpg'"," 'c.jpg]"]. here a,b,c,e,f are images urls actually.

  • you need to know if you have a list or a string before using `explode`, this is already covered in many answers, make sure you identify which type you have to debug your issue. In you case it looks like you can first use `pd.eval` to transform to lists OR use a regex+findall to extract the substrings inside the quotes. – mozway May 18 '22 at 07:39

0 Answers0