- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
How to calculate the frequency of each item in a Pandas series?
In this program, we will calculate the frequency of each element in a Pandas series. The function value_counts() in the pandas library helps us to find the frequency of elements.
Step 1: Define a Pandas series. Step 2: Print the frequency of each item using the value_counts() function.
import pandas as pd series = pd.Series([10,10,20,30,40,30,50,10,60,50,50]) print("Series:\n", series) frequency = series.value_counts() print("\nFrequency of elements:\n", frequency)
Series: 0 10 1 10 2 20 3 30 4 40 5 30 6 50 7 10 8 60 9 50 10 50 dtype: int64 Frequency of elements: 50 3 10 3 30 2 20 1 40 1 60 1 dtype: int64
- Related Articles
- How to calculate the absolute values in a pandas series with complex numbers?
- How to check each value of a pandas series is unique or not?\n
- Python - Repeat each element of a Pandas Series in a dissimilar way
- How to sort a Pandas Series?
- How to get the nth percentile of a Pandas series?
- How to check the data type of a pandas series?
- How to append a pandas Series object to another Series in Python?
- How to count frequency of itemsets in Pandas DataFrame
- Python Pandas - Extract the minute from DateTimeIndex with specific time series frequency
- Python Pandas - Extract year from the DateTimeIndex with specific time series frequency
- Python Pandas - Extract the day of week from the DateTimeIndex with specific time series frequency
- How to Get the Position of Max Value of a pandas Series?
- How to Get the Position of Minimum Value of a pandas Series?
- Python Pandas - Extract the hour from the DateTimeIndex with specific time series frequency
- Python Pandas - Extract the seconds from the DateTimeIndex with specific time series frequency