当列中有列表对象时获取 pandas Dataframe 中唯一值的计数
Getting count of unique values in pandas Dataframe when there is a list object in a column
基本上我是在尝试分析 Instagram 帐户。我已经使用 selenium 抓取了 intagram 并创建了一个数据框,其中包含指向 post 的链接、喜欢的数量和使用的主题标签。所以在数据框中,我在一个 cloumn 中包含了列表对象,我想找到总共使用的唯一主题标签的数量。
这就是数据框的样子。
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 的列表对象。有没有更好的方法来存储主题标签?以及如何获取整体使用的唯一主题标签的数量。
提前致谢!!
这是使用 Counter
的一种方法:
from collections import Counter
arr = df['hashtags'].apply(pd.Series).values.ravel() # Consolidate all hashtags
count_dict = Counter(arr)
基本上我是在尝试分析 Instagram 帐户。我已经使用 selenium 抓取了 intagram 并创建了一个数据框,其中包含指向 post 的链接、喜欢的数量和使用的主题标签。所以在数据框中,我在一个 cloumn 中包含了列表对象,我想找到总共使用的唯一主题标签的数量。
这就是数据框的样子。
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 的列表对象。有没有更好的方法来存储主题标签?以及如何获取整体使用的唯一主题标签的数量。
提前致谢!!
这是使用 Counter
的一种方法:
from collections import Counter
arr = df['hashtags'].apply(pd.Series).values.ravel() # Consolidate all hashtags
count_dict = Counter(arr)