[英]Splitting a a string into a list of items in pandas dataframe | Python | Pandas |
I have a panda dataframe where column values like:我有一个熊猫 dataframe ,其中列值如下:
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:预期 Output:
0 [note, pen]
1 [paper, pencil]
2 [note, pen]
I try the below method, but i not getting the expected output:我尝试了以下方法,但没有得到预期的 output:
df_['products'] = [list(map(str, i.split())) for i in df_['products']]
Are you just trying to make numpy arrays into lists ?您是否只是想将numpy arrays 放入列表中?
df_['products'].apply(lambda x: x.to_list())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.