我想加入一个数据帧中的元组列表。
我尝试过在数据帧中使用join
和lambda
实现这一点的几种方法
import pandas as pd
from nltk import word_tokenize, pos_tag, pos_tag_sents
data = {'Categories': ['animal','plant','object'],
'Type': ['tree','dog','rock'],
'Comment': ['The NYC tree is very big', 'NY The cat from the UK is small',
'The rock was found in LA.']}
def posTag(data):
data = pd.DataFrame(data)
comments = data['Comment'].tolist()
taggedComments = pos_tag_sents(map(word_tokenize,comments))
data['taggedComment'] = taggedComments
print data['taggedComment']
data['taggedComment'].apply(lambda x: (' '.join(x)))
return data
taggedData = posTag(data)
print data
我尝试过的其他一些tuple
连接方法有:
不管我做什么,我都会犯同样的错误。在
TypeError: sequence item 0: expected string, tuple found
我想要的回答是
[('A', 'B'), ('B', 'C'), ('C', 'B')]
在要输出文件的数据帧中
'A_B B_C C_B'
关于出什么问题有什么建议吗?在
可以使用double
list comprehension
并将输出分配给column back:所以不是:
{cd2>在下面的方法中使用:
^{pr2}$总而言之:
相关问题 更多 >
编程相关推荐