Home > front end >  convert sentences in a column to list in pandas dataframe
convert sentences in a column to list in pandas dataframe

Time:11-16

My current dataframe looks like this

A header Another header
First i like apple
Second alex is friends with jack

I am expecting

A header Another header
First [i, like, apple]
Second [alex, is, friends, with, jack]

How can I accomplish this efficiently?

CodePudding user response:

You can use standard str operations on the column:

df['Another header'] = df['Another header'].str.split()

CodePudding user response:

Use Series.str.split:

df['Another header'] = df['Another header'].str.split()

CodePudding user response:

You can use map with a lambda function

df['Another header'] = list(map(lambda x: x.split(' '), df['Another header']))
  • Related