
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Missing Element in a Series Using Python
Solution
To solve this, we will follow the steps given below −
Define a Series.
Create a for loop and access the data from start to end elements. Set if condition to check the data is present or not.
If the value is not in the range then append it to the list. Finally, sort and print the values.
for i in range(data[0],data[length-1]): if(i not in data): l1.append(i) else: l1.append(i)
Example
Let us see the following implementation to get a better understanding.
import pandas as pd import numpy as np l = [1,2,3,6,7] l1 = [] data = pd.Series(l) length = len(data) for i in range(data[0],data[length-1]): if(i not in data): l1.append(i) else: l1.append(i) l1.sort() data = pd.Series(l1) print(data)
Output
0 1 1 2 2 3 3 4 4 5 5 6
Advertisements