需要将Pandas DataFrame转换为列表列表?

时间:2017-03-23 11:06:42

标签: python list pandas dataframe

我使用下面的代码来获取列表。

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

1 个答案:

答案 0 :(得分:1)

[ s.split(',') for s in df['Column'].values.tolist()]

或可能

df['Column'].str.split(',').values.tolist()