如何从 DataFrame 列中的长字符串生成列表列表?

How do you generate a List of Lists from Long Strings in a DataFrame Column?

有一个非常尴尬的设置。我在第二列中有一个带有长字符串的 DataFrame,我想将其分解并转换为列表列表。

   col1  col2      
0  P     mary jane clare     
1  Q     tom dick harry     
2  R     sam jack bill    

我想要以下列表列表作为输出:

[["mary", "jane", "clare"],["tom", "dick", "harry"],["sam", "jack", "bill"]]

非常不确定如何处理这个问题。

万分感谢。

使用白色拆分 col2 space 然后应用 to_list() 方法得出一个列表

df['col2'].str.split('\s').to_list()