 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Write a program in Python to find the index for NaN value in a given series
Input −
Assume, you have a series,
0 1.0 1 2.0 2 3.0 3 NaN 4 4.0 5 NaN
Output −
And, the result for NaN index is,
index is 3 index is 5
Solution
To solve this, we will follow the steps given below −
- Define a Series. 
- Create for loop and access all the elements and set if condition to check isnan(). Finally print the index position. It is defined below, 
for i,j in data.items(): if(np.isnan(j)):    print("index is",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,np.nan,4,np.nan] data = pd.Series(l) print(data) for i,j in data.items():    if(np.isnan(j)):       print("index is",i)  Output
0 1.0 1 2.0 2 3.0 3 NaN 4 4.0 5 NaN dtype: float64 index is 3 index is 5
Advertisements
 