Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 1
    Good to know I am not the only one who thought that OPs dataframe looks exactly the way he mentioned (no comma between red and blue). That is why I deleted my answer (I had assumed he made a typo) initially too. Anyway, I like this solution, couldnt think of that. Thanks. :) Commented Aug 12, 2019 at 6:57
  • Actually, that is the point! In my dataframe it does not have comma, is like I wrote initially (a mod edited my question putting the comma). What I have is data of type "object" and is like ['red' 'blue']. Thank you both, I am going to try such solutions and I will come back. Commented Aug 12, 2019 at 7:00
  • Do you also have it as ['red' 'blue'] and not [red blue] <- without quotes Commented Aug 12, 2019 at 7:02
  • @EAlvarado - Is possible use df['Column2'] = df['Column2'].str.replace(' ', ', ').apply(ast.literal_eval) before my solution? Commented Aug 12, 2019 at 7:04
  • @Ankur Sinha - They have quotes (single quote) @jezrael - I tried but I have the following error ValueError: malformed node or string: nan. I would like actually to keep the original format if possible. Commented Aug 12, 2019 at 7:12