字符串数组判刑数据帧大熊猫

问题描述:

我的数据框的样子字符串数组判刑数据帧大熊猫

Phrase           Sentiment 
[seri, escapad, demonstr, adag, good, goos]   1 
[seri, escapad, demonstr, adag, good, goos]   2 

当我使用命令df.dtypes

Phrase  object 
Sentiment  int64 
dtype: object 

我需要得到这样一个数据帧:

Phrase           Sentiment 
seri escapad demonstr adag good goos   1 
seri escapad demonstr adag good bad    2 

我试过这个代码

df['Phrase'] = df[df.Phrase.map(lambda x: ','.join(x))] 

我应该做的id

+0

你好,你可以将列表转换成字符串...但是..你想用DF做什么? – Ika8

+0

@ Ika8情绪分析 –

差不多吧 - 你的df[一个额外层。试试这个:

df['Phrase'] = df.Phrase.map(lambda x: ' '.join(x)) 

您已经返回要用来替换Phrase列,但随后你被它的价值,这是产生错误试图索引。

我觉得你很亲密。下面一行应该做的伎俩:

df['Phrase'] = df['Phrase'].map(lambda x: ' '.join(x)) 

使用 ' '不是','

你可以不用拉姆达这样的:

df['Phrase'] = df.Phrase.apply(', '.join) 

使用lambda:

df['Phrase'] = df.Phrase.apply(lambda x: ', '.join(x))