
- 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
Write a program in Python to find the most repeated element in a series
Assume, you have the following series,
Series is: 0 1 1 22 2 3 3 4 4 22 5 5 6 22
And the result for the most repeated element is,
Repeated element is: 22
Solution
To solve this, we will follow the below approach,
Define a series
Set initial count is 0 and max_count value as series first element value data[0]
count = 0 max_count = data[0]
Create for loop to access series data and set frequency_count as l.count(i)
for i in data: frequency_count = l.count(i)
Set if condition to compare with max_count value, if the condition is true then assign count to frequency_count and change max_count to series present element. Finally, print the max_count. It is defined below,
if(frequency_count > max_count): count = frequency_count max_count = i print("Repeated element is:", max_count)
Example
Let’s see the below implementation to get a better understanding −
import pandas as pd l = [1,22,3,4,22,5,22] data = pd.Series(l) print("Series is:\n", data) count = 0 max_count = data[0] for i in data: frequency_count = l.count(i) if(frequency_count > max_count): count = frequency_count max_count = i print("Repeated element is:", max_count)
Output
Series is: 0 1 1 22 2 3 3 4 4 22 5 5 6 22 dtype: int64 Repeated element is: 22
- Related Articles
- Write a program in Python to print the most frequently repeated element in a series
- Write a program in Python to find the missing element in a given series and store the full elements in the same series
- C++ program to find Second most repeated word in a sequence
- Write a program in Python to slice substrings from each element in a given series
- How to Find the Most Repeated Word in a Text File using Python?
- Write a program in C++ to find the most frequent element in a given array of integers
- Write a program in Python to calculate the default float quantile value for all the element in a Series
- Write a program in Python to find the index for NaN value in a given series
- Write a program in Python to find the maximum length of a string in a given Series
- Program to find frequency of the most frequent element in Python
- Second most repeated word in a sequence in Python?
- Write a Java program to find the first array element whose value is repeated an integer array?
- Program to find out the index of the most frequent element in a concealed array in Python
- Find most frequent element in a list in Python
- Find the second most repeated word in a sequence in Java

Advertisements