首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当列中有list对象时,获取大熊猫Dataframe中唯一值的计数

当列中有list对象时,获取大熊猫Dataframe中唯一值的计数
EN

Stack Overflow用户
提问于 2021-02-25 14:28:11
回答 1查看 66关注 0票数 1

所以基本上我是在分析instagram账户。我已经使用selenium刮过intagram,并创建了一个数据栏,其中包括到post的链接、喜欢的数量和使用的哈希标签。因此,在数据框架中,我已经将list对象包含在一个cloumn中,并且我希望找到总计使用的唯一哈希标签的计数。

这就是这个数据文件的样子。

代码语言:javascript
复制
                                      links  ...                                           hashtags
0  https://www.instagram.com/p/CLrU5s5g7L7/  ...  [#data, #datascience, #technology, #machinelea...
1  https://www.instagram.com/p/CLojnLQgEVs/  ...  [#datascience, #machinelearning, #python, #art...
2  https://www.instagram.com/p/CLjhzPxgpkM/  ...  [#python, #AI, #ML, #artificialintelligence, #...
3  https://www.instagram.com/p/CLgUsXAgOah/  ...  [#datascience, #machinelearning, #python, #art...
4  https://www.instagram.com/p/CLdfVBHAibb/  ...  [#billgates, #softwareengineering, #softwareen...
5  https://www.instagram.com/p/CLbGqrYgl74/  ...  [#python3, #python, #pythonprogramming, #AI, #...
6  https://www.instagram.com/p/CLZKOEcg72M/  ...  [#python3, #python, #pythonprogramming, #AI, #...
7  https://www.instagram.com/p/CLYe9AJgg0U/  ...  [#datascience, #machinelearning, #python, #art...
8  https://www.instagram.com/p/CLV4UP5Af-2/  ...  [#pawrihoraihai, #programming, #coding, #progr...
9  https://www.instagram.com/p/CLTSxc5g2cJ/  ...  [#datascience, #machinelearning, #python, #art..

我已经将哈希标记存储为与相应的post对应的list对象。有没有更好的方法来存储标签呢?以及如何获得整体使用的唯一标签的计数。

提前谢谢!!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-25 15:06:39

这里有一种使用Counter的方法

代码语言:javascript
复制
from collections import Counter

arr = df['hashtags'].apply(pd.Series).values.ravel()  # Consolidate all hashtags
count_dict = Counter(arr)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66370453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档