Python 迭代具有列表值的列并将其存储在新列中

Python 迭代具有列表值的列并将其存储在新列中,python,pandas,Python,Pandas,我有一个熊猫数据框,如图所示: text 0 [is, upset, that, he, cant, update, his, faceb... 1 [dived, many, time, for, the, ball, managed, t... 2 [my, whole, body, feel, itchy, and, like, it, ... 3 [no, it, not, behaving, at, all, im, mad, why,... 4 [not,

我有一个熊猫数据框,如图所示:

    text
0   [is, upset, that, he, cant, update, his, faceb...
1   [dived, many, time, for, the, ball, managed, t...
2   [my, whole, body, feel, itchy, and, like, it, ...
3   [no, it, not, behaving, at, all, im, mad, why,...
4   [not, the, whole, crew]
我希望dataframe文本列只包含

    text
0   is upset that he cant update his faceb...
1   dived many time for the ball managed t...
2   my whole body feel itchy and like it ...
3   no it not behaving at all im mad why...
4   not the whole crew
我尝试了以下方法,但似乎不起作用:

df['text'] = df['text'].apply(lambda x: x[0])

想知道我遗漏了什么吗?

将列表转换为行的最简单方法是使用
explode()


使用
列表理解

df['text'] = [' '.join(map(str, li)) for li in df['text']]

df['text']=df['text'].str.join(“”)
?应该是
。应用(lambda x:'.join([str(elem)表示x中的元素))
@QuangHoang的解决方案成功了!谢谢。这里explode没有帮助,OP想要加入数组中的值。这会给出一个错误:“TypeError:“float”对象不可编辑”你有任何nan吗?没有。让我试试这个:“.apply(lambda x:”.join([str(elem)表示x中的elem])”,如您所述。
df['text'] = [' '.join(map(str, li)) for li in df['text']]