
- 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
Python Pandas – Check and Display row index with infinity
To check and display row index, use the isinf() with any(). At first, let us import the required libraries with their respective aliases −
import pandas as pd import numpy as np
Create a dictionary of list. We have set the infinity values using the Numpy np.inf −
d = { "Reg_Price": [7000.5057, np.inf, 5000, np.inf, 9000.75768, 6000, 900, np.inf] }
Creating DataFrame from the above dictionary of list −
dataFrame = pd.DataFrame(d)
Getting row index with infinity values −
indexNum = dataFrame.index[np.isinf(dataFrame).any(1)]
Example
Following is the code −
import pandas as pd import numpy as np # dictionary of list d = { "Reg_Price": [7000.5057, np.inf, 5000, np.inf, 9000.75768, 6000, 900, np.inf] } # creating dataframe from the above dictionary of list dataFrame = pd.DataFrame(d) print"DataFrame...\n",dataFrame # checking for infinite values and displaying the count count = np.isinf(dataFrame).values.sum() print"\nInfinity values count...\n ",count # getting row index with infinity values indexNum = dataFrame.index[np.isinf(dataFrame).any(1)] print"\nDisplay row indexes with infinite values...\n ",indexNum
Output
This will produce the following output −
DataFrame... Reg_Price 0 7000.505700 1 inf 2 5000.000000 3 inf 4 9000.757680 5 6000.000000 6 900.000000 7 inf Infinity values count... 3 Display row indexes with infinite values... Int64Index([1, 3, 7], dtype='int64')
- Related Articles
- Python - Check if Pandas dataframe contains infinity
- Python Pandas - Check if the index is empty with 0 elements
- Python Pandas - Check if the Pandas Index holds Interval objects
- How to display Pandas Dataframe in Python without Index?
- Python Pandas - Check if the index has NaNs
- Python Pandas - Display the index of dataframe in the form of multi-index
- Python - Check if the Pandas Index with some NaNs is a floating type
- Python - Check if the Pandas Index holds categorical data
- Python Pandas - Check if the index has unique values
- Python Pandas - Check if the index has duplicate values
- Python - Make new Pandas Index with deleting multiple index elements
- Python - Check if the Pandas Index only consists of booleans
- Python - Check if the Pandas Index is a floating type
- Python - Check if the Pandas Index only consists of integers
- Python Pandas - Return Index with duplicate values removed

Advertisements