
- 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 - Check if the Pandas Index only consists of numeric data
To check if the Pandas Index only consists of numeric data, use the index.is_numeric() method. At first, import the required libraries -
import pandas as pd import numpy as np
Creating Pandas index with integer, float and NaNs
index = pd.Index([5, 10.2, 25, 50, 75.2, 100, np.nan])
Display the Pandas index −
print("Pandas Index...\n",index)
Check whether index values has only numeric data. Numeric data includes integer, floats and NaNs −
index.is_numeric()
Example
Following is the code −
import pandas as pd import numpy as np # Creating Pandas index with integer, float and NaNs index = pd.Index([5, 10.2, 25, 50, 75.2, 100, np.nan]) # Display the Pandas index print("Pandas Index...\n",index) # Return the number of elements in the Index print("\nNumber of elements in the index...\n",index.size) # Return the dtype of the data print("\nThe dtype object...\n",index.dtype) # Check whether index values has only numeric data. # Numeric data includes integer, floats and NaNs print("\nIndex values only consists of numeric data?\n",index.is_numeric())
Output
This will produce the following output −
Pandas Index... Float64Index([5.0, 10.2, 25.0, 50.0, 75.2, 100.0, nan], dtype='float64') Number of elements in the index... 7 The dtype object... float64 Index values only consists of numeric data? True
- Related Articles
- Python - Check if the Pandas Index only consists of booleans
- Python - Check if the Pandas Index only consists of integers
- Python - Check if the Pandas Index holds categorical data
- Python Pandas - Check if the Pandas Index holds Interval objects
- Python Pandas - Check if the index has NaNs
- Python - Check if the Pandas Index is of the object dtype
- Python Pandas - Check if the index has unique values
- Python Pandas - Check if the index has duplicate values
- Python - Check if the Pandas Index is a floating type
- Python Pandas - Check if the index is empty with 0 elements
- How to check if a unicode string contains only numeric characters in Python?
- Python Pandas - Return if the index is monotonic increasing (only equal or increasing) values
- Python Pandas - Return if the index is monotonic decreasing (only equal or decreasing) values
- Python - Check if the Pandas Index with some NaNs is a floating type
- Python Pandas - Return the number of bytes in the underlying Index data

Advertisements