我的数据框看起来像
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))]
我应该做什么
最佳答案
几乎正确——你有一个额外的层 df[
。试试这个:
df['Phrase'] = df.Phrase.map(lambda x: ' '.join(x))
您已经返回了要用于替换 Phrase
的列,但随后您试图按其值进行索引,这会产生错误。
关于python - 一个字符串数组到句子数据框 pandas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42211208/