0

I have a following dataframe:

ID  Skills
1   []
2   []
3   ['seo']
4   ['design', 'security', 'css', 'javascript']
5   ['design']

Now, I want to create a new dataframe like below:

ID  Skills
1   None
2   None
3   seo
4   design
4   security
4   css
4   javascript
5   design

I tried using nested for loop with to iterate over individual strings, but its not giving the desired result. Also, tried the following code as well but no luck in either case.

ids = []
skills = []

for id, d in df.iteritems():
    ids.append(id)
    skills.append(pd.DataFrame(d))

pd.concat(skills, keys=ids)
Saurabh
  • 121
  • 12
  • Use: `df.explode("Skills")` – Erfan Sep 09 '20 at 18:36
  • @Erfan I tried .explode(), but this isn't working. I guess explode() works with list of lists and in my example " ['design', 'security', 'css', 'javascript'] ". I thought may be " " causing the issue, so even tried removing them, but I think because of these quotes its considering all strings as single and not unpacking them. I even tried removing all quotes but could not remove, got like '[design, security, css, javascript]'. – Saurabh Sep 11 '20 at 03:12

0 Answers0