यह जाँचने के लिए कि क्या पंडों के सूचकांक में केवल संख्यात्मक डेटा है, index.is_numeric() का उपयोग करें तरीका। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd import numpy as np
पूर्णांक, फ्लोट और NaNs के साथ पांडा अनुक्रमणिका बनाना
index = pd.Index([5, 10.2, 25, 50, 75.2, 100, np.nan])
पांडा सूचकांक प्रदर्शित करें -
print("Pandas Index...\n",index) जांचें कि क्या अनुक्रमणिका मानों में केवल संख्यात्मक डेटा है। संख्यात्मक डेटा में पूर्णांक, फ्लोट और NaN शामिल होते हैं -
index.is_numeric()
उदाहरण
निम्नलिखित कोड है -
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()) आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
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