2

I have a dataframe as following:

id|words
1|ant,bat,cat
2|mat,rat,pat

I want the words column to be as follows:

id|words
1|['ant','bat','cat']
2|['mat','rat','pat']

How could I do it? I tried with literaleval but it shows exception

4
  • dupe not match, reopened. Commented Jun 2, 2020 at 14:08
  • @jezrael why you think that is not dup ? from what I saw only the sep is different Commented Jun 2, 2020 at 14:09
  • @YOBEN_S - Answer is about first value of splitted separator. Commented Jun 2, 2020 at 14:19
  • @jezrael before they get the first value , it save whole list I think Commented Jun 2, 2020 at 14:22

1 Answer 1

3

Use Series.str.split:

df['words'] = df['words'].str.split(',')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.