यह जांचने के लिए कि क्या सूचकांक में NaN है, index.hasnans . का उपयोग करें पंडों में संपत्ति।
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd import numpy as np
सूचकांक बनाना। NaN के लिए, हमने सुन्न पुस्तकालय का उपयोग किया है -
index = pd.Index(['Car','Bike', np.nan,'Car',np.nan, 'Ship'])
सूचकांक प्रदर्शित करें -
print("Pandas Index...\n",index) जांचें कि क्या सूचकांक में NaN है -
print("\nIs the Pandas index having NaNs?\n",index.hasnans)
उदाहरण
निम्नलिखित कोड है -
import pandas as pd
import numpy as np
# Creating the index
# For NaN, we have used numpy library
index = pd.Index(['Car','Bike', np.nan,'Car',np.nan, 'Ship'])
# Display the index
print("Pandas Index...\n",index)
# Return an array representing the data in the Index
print("\nArray...\n",index.values)
# Check if the index is having NaNs
print("\nIs the Pandas index having NaNs?\n",index.hasnans)
# Return a tuple of the shape of the underlying data
print("\nA tuple of the shape of underlying data...\n",index.shape) आउटपुट
यह निम्नलिखित कोड उत्पन्न करेगा -
Pandas Index... Index(['Car', 'Bike', nan, 'Car', nan, 'Ship'], dtype='object') Array... ['Car' 'Bike' nan 'Car' nan 'Ship'] Is the Pandas index having NaNs? True A tuple of the shape of underlying data... (6,)