我使用下面的代码来获取列表。
df['Column'].values.tolist()
Pandas DataFrame会返回这样的数据
['tropical fruit,yogurt,coffee', 'pip fruit','yogurt,cream cheese ,meat spreads', 'whole milk','butter,yogurt,rice,abrasive cleaner']
但我需要得到像这样的数据
[['tropical fruit','yogurt','coffee'],['pip fruit'],['yogurt','cream cheese' ,'meat spreads'],['whole milk'],['butter','yogurt','rice','abrasive cleaner']]
答案 0 :(得分:1)
[ s.split(',') for s in df['Column'].values.tolist()]
或可能
df['Column'].str.split(',').values.tolist()