[英]convert List of List to a single column in Dataframe
我有一个熊猫数据框,如下所示:
comments tags
===============================
Hello I am fine #askfine #tag1
How are you ? #ask # tag2
我有以下列表列表:
[['Hello', 'I', 'am', 'fine'], ['How', 'are', 'you', '?']]
现在,我想将下面的列表列表作为一列附加到原始数据框。
comments tags processed_comments
==============================================================
Hello I am fine #askfine #tag1 ['Hello', 'I', 'am', 'fine']
How are you ? #ask # tag2 ['How', 'are', 'you', '?']
我该怎么办?
df['processed_comments'] = listOfList
无法正常工作。
谢谢
l = [['Hello', 'I', 'am', 'fine'], ['How', 'are', 'you', '?']]
您可以使用:
df['processed_comments'] = l
df
comments processed_comments
0 Hello I am fine [Hello, I, am, fine]
1 How are you ? [How, are, you, ?]
每个列表元素都被视为该行的值。 因此,请确保列表的长度(即列表内部的列表)等于行数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.