Рассчитайте частоту каждого уникального значения серии Pandas
Опубликовано: 27 Марта, 2022
Давайте посмотрим, как найти частоту каждого уникального значения серии Pandas. Мы будем использовать функцию value_counts () для выполнения этой задачи.
Example 1 :
# importing the moduleimport pandas as pd # creating the seriess = pd.Series(data = [2, 3, 4, 5, 5, 6, 7, 8, 9, 5, 3]) # displaying the seriesprint(s) # finding the unique countprint(s.value_counts()) |
Output :
Output:
Example 2 :
# importing the moduleimport pandas as pd # creating the seriess = pd.Series(np.take(list("0123456789"), np.random.randint(10, size = 40))) # displaying the seriesprint(s) # finding the unique counts.value_counts() |
Output :
Output:
Example 3 :
# importing pandas as pd import pandas as pd # creating the Series sr = pd.Series(["Mumbai", "Pune", "Agra", "Pune", "Goa", "Shimla", "Goa", "Pune"]) # displaying the series print(sr) # finding the unique countsr.value_counts() |
Output :

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course