对于Pandas Dataframe中的每个元素,将列表元素拆分为单词的子列表

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

我正在尝试使dataframe列看起来像这样:

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列中

转载请注明出处:http://www.bqysc.com/article/20230526/1575049.html