【发布时间】:2020-12-29 07:15:06
【问题描述】:
split list elements into sub-elements in pandas dataframe 这个非常接近 - 但不是将所有元素拆分并放入一个列表中,我需要将它们放入一个子列表中。
df:
col1
['this is list 1', 'this is list 2', 'this is another list 3']
['this is list 1', 'this is list 2', 'this is another list 3']
['this is list 1', 'this is list 2', 'this is another list 3']
我正在尝试使数据框列看起来像这样:
col1
[['this', 'is', 'list', '1'], ['this', 'is', 'list', '2'], ['this', 'is', 'another', lis't', '3']]
[['this', 'is', 'list', '1'], ['this', 'is', 'list', '2'], ['this', 'is', 'another', lis't', '3']]
[['this', 'is', 'list', '1'], ['this', 'is', 'list', '2'], ['this', 'is', 'another', lis't', '3']]
基本上将列表中的元素拆分为子列表,其中每个单词都是子列表中的元素/项目,都在 pandas df 列中
【问题讨论】:
-
我最初的想法是申请
lambda l: [s.split() for s in l] -
@ifly6 噢噢噢火。做完儿子。谢谢