
- 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 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
- Related Articles
- Write a Python program to find the maximum value from first four rows in a given series
- Write a program in Python to print numeric index array with sorted distinct values in a given series
- Write a program in Python to find the maximum length of a string in a given Series
- Write a program in Python to replace all odd index position in a given series by random uppercase vowels
- Write a program in Python to verify kth index element is either alphabet or number in a given series
- Program to find maximum value at a given index in a bounded array in Python
- Write a Python program to shuffle all the elements in a given series
- Write a program in Python to round all the elements in a given series
- Write a program in Python to filter valid dates in a given series
- Write a program in Python to filter armstrong numbers 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
- 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 transpose the index and columns in a given DataFrame
- Write a program in Python to generate five random even index lowercase alphabets in a series
- Write a program to truncate a dataframe time series data based on index value

Advertisements