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']))
