 
  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
Python - Check if Pandas dataframe contains infinity
To check, use the isinf() method. To find the count of infinite values, use sum(). 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] }  Creating dataframe from the above dictionary of list
dataFrame = pd.DataFrame(d)
Checking for infinite values using isinf() and displaying the count
count = np.isinf(dataFrame).values.sum()
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] } # 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...\n ",count  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 Infinity values... 2
Advertisements
 