

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Python - Display True for infinite values in a Pandas DataFrame
Use the isin() method to display True for infinite values. 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)
Display True for infinite values −
res = dataFrame.isin([np.inf, -np.inf])
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 # Displaying TRUE for infinite values res = dataFrame.isin([np.inf, -np.inf]) print"\n Updated DataFrame...\n",res
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 Updated DataFrame... Reg_Price 0 False 1 True 2 False 3 True 4 False 5 False 6 False 7 True
- Related Questions & Answers
- Python - Remove duplicate values from a Pandas DataFrame
- Python Pandas - Display specific number of rows from a DataFrame
- Python - Draw a Scatter Plot for a Pandas DataFrame
- How to display Pandas Dataframe in Python without Index?
- Python - Compute last of group values in a Pandas DataFrame
- Python - Compute first of group values in a Pandas DataFrame
- Python Pandas – Display all the column names in a DataFrame
- Python Pandas - Indicate all duplicate index values as True
- Python – Display only non-duplicate values from a DataFrame
- Merge Python Pandas dataframe with a common column and set NaN for unmatched values
- Python - Replace values of a DataFrame with the value of another DataFrame in Pandas
- Compare specific Timestamps for a Pandas DataFrame – Python
- Python - Search DataFrame for a specific value with pandas
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- Python - Round number of places after the decimal for column values in a Pandas DataFrame
Advertisements