इंडेक्स ऑब्जेक्ट में निर्दिष्ट मान के साथ NaN मान भरने के लिए, index.fillna() का उपयोग करें पंडों में विधि। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd import numpy as np
कुछ NaN मानों के साथ-साथ पंडों का अनुक्रमणिका बनाना -
index = pd.Index([50, 10, 70, np.nan, 90, 50, np.nan, np.nan, 30])
पांडा सूचकांक प्रदर्शित करें -
print("Pandas Index...\n",index) NaN को कुछ विशिष्ट मान से भरें -
print("\nIndex object after filling NaN value...\n",index.fillna('Amit'))
उदाहरण
निम्नलिखित कोड है -
import pandas as pd
import numpy as np
# Creating Pandas index with some NaN values as well
index = pd.Index([50, 10, 70, np.nan, 90, 50, np.nan, np.nan, 30])
# 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)
# Fill the NaN with some specific value
print("\nIndex object after filling NaN value...\n",index.fillna('Amit')) आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
Pandas Index... Float64Index([50.0, 10.0, 70.0, nan, 90.0, 50.0, nan, nan, 30.0], dtype='float64') Number of elements in the index... 9 The dtype object... float64 Index object after filling NaN value... Index([50.0, 10.0, 70.0, 'Amit', 90.0, 50.0, 'Amit', 'Amit', 30.0], dtype='object')