
- 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 print the most frequently repeated element in a series
Input − Assume, you have a Series,
0 1 1 2 2 3 3 2 4 3 5 3 6 3 7 4 8 4 9 2
Output − And, the result for a most repeated element is 3.
Solution
To solve this, we will follow the steps given below −
Define a Series
Apply functools reduce method inside lambda function to compare the length of all the elements one by another. It is defined below,
ft.reduce(lambda x,y:x if(len(data[data==x])>len(data[data==y])) else y,data)
Example
Let us see the following implementation to get a better understanding.
import pandas as pd import functools as ft l = [1,2,3,2,3,3,3,4,4,2] data = pd.Series(l) print("most repeated element is:", ft.reduce(lambda x,y:x if(len(data[data==x])>len(data[data==y])) else y,data))
Output
most repeated element is: 3
- Related Articles
- Write a program in Python to find the most repeated element in a series
- Write a program in Python to print the elements in a series between a specific range
- Write a program in Python to print the power of all the elements in a given series
- Write a program in Python to print the day of the year in a given date series
- Write a Golang program to print the Fibonacci series
- Write a program in Python to slice substrings from each element in a given series
- Write a program in Python to find the missing element in a given series and store the full elements in the same series
- How to Identify Most Frequently Occurring Items in a Sequence with Python?
- 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 print numeric index array with sorted distinct values in a given series
- Second most repeated word in a sequence in Python?
- Write a program in Python to print the first and last three days from a given time series data
- C++ program to find Second most repeated word in a sequence
- Write a program in C++ to find the most frequent element in a given array of integers
- Write a Python program to shuffle all the elements in a given series

Advertisements