我有两列:df[upvotes]
和df[headline]
。headlines列包含带有标题字符串的行,upvots列只是带有整数的行。在
使用pandas,我想找出标题中哪个词的数量最有利于投票。在
最好的办法是什么?在
到目前为止,apply方法将一个序列传递给x
,因此显然我不太理解这是如何工作的。在
df.groupby('upvotes')['headline'].apply(lambda x: len(x.split(' '))).sort_index(ascending=False)
前5行数据:
^{pr2}$
Tags:
如果我理解您的问题,您可以使用
groupby.mean
来解决这个问题。如果需要,可以用groupby.sum
替换。在一般来说,最好尽可能避免
lambda
函数。在相关问题 更多 >
编程相关推荐