yyz_vanvlet
yyz_vanvlet

Reputation: 191

How to transform series in a column to list in a column in a pandas dataframe?

i have a column that has a series of words and i need to transform it to a list and assign to the same column. I tried with a for loop but it has so many lines it takes too long

Here's the dataset:

   name      hobbies
0  James     "study","play"
1  Harden    "dance,"jump"

And i need to transform it to:

   name    hobbies
0  James   ["study","play"]
1  Harden  ["dance","jump"]

Upvotes: 1

Views: 26

Answers (1)

jezrael
jezrael

Reputation: 862511

Use Series.str.split:

df['hobbies'] = df['hobbies'].str.split(',')

Upvotes: 1

Related Questions