熊猫:将行的一部分转换为列表

时间:2018-09-06 01:47:27

标签: python python-3.x pandas

我有一个看起来像这样的数据框:

df2 = pd.DataFrame(['Apple, eggs, pineapple pizza', 'orange, soda, pepsi, cola', 'pear, watermelon, pizza, lasagna', 'apple, eggs, human sandwich, human chili'], columns=['A'])

                                          A
0              Apple, eggs, pineapple pizza
1                 orange, soda, pepsi, cola
2          pear, watermelon, pizza, lasagna
3  apple, eggs, human sandwich, human chili

我要输出的是这样:

['apple, eggs, pineapple, pizza', 'orange, soda, pepsi, cola', 'pear, watermelon, pizza, lasagna', 'apple, eggs, human sandwich, human chili']

我不确定从哪里开始,有什么建议吗?

1 个答案:

答案 0 :(得分:1)

这是您需要的吗?

df2.A.values.tolist()
Out[412]: 
['Apple, eggs, pineapple pizza',
 'orange, soda, pepsi, cola',
 'pear, watermelon, pizza, lasagna',
 'apple, eggs, human sandwich, human chili']