简体   繁体   中英

Splitting a a string into a list of items in pandas dataframe | Python | Pandas |

I have a panda dataframe where column values like:

0    ['note' 'pen']
1    ['paper' 'pencil']
2    ['note' 'pen']

I want to make the values in column, that contain a list of all different items that is get after splitting each values.

Expected Output:

0   [note, pen]
1   [paper, pencil]
2   [note, pen]

I try the below method, but i not getting the expected output:

df_['products'] = [list(map(str, i.split())) for i in df_['products']]

Are you just trying to make numpy arrays into lists ?

df_['products'].apply(lambda x: x.to_list())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM