- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Algorithm
Step 1: Define a Pandas series. Step 2: Print the frequency of each item using the value_counts() function.
Example Code
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)
Output
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
Advertisements