【发布时间】:2023-04-04 04:04:01
【问题描述】:
我有两列:df[upvotes] 和 df[headline]。标题列包含带有标题字符串的行,而upvotes 列只是带有整数的行。
使用 pandas,我想找出标题中的哪些字词获得最多支持。
最好的方法是什么?
到目前为止我有这个,但是 apply 方法将一个系列传递给x,所以显然我不明白它是如何运作的。
df.groupby('upvotes')['headline'].apply(lambda x: len(x.split(' '))).sort_index(ascending=False)
前5行数据:
upvotes headline
0 1 Software: Sadly we did adopt from the construc...
1 1 Google’s Stock Split Means More Control for L...
2 1 SSL DOS attack tool released exploiting negoti...
3 67 Immutability and Blocks Lambdas and Closures
4 1 Comment optimiser la vitesse de Wordpress?
【问题讨论】: