কম্পিউটার

Python Pandas - একটি সূচক বস্তুতে নির্দিষ্ট মান দিয়ে NaN মান পূরণ করুন


একটি সূচক বস্তুতে নির্দিষ্ট মান দিয়ে 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')

  1. পাইথন - পান্ডাসে গড় সহ NAN মানগুলি কীভাবে পূরণ করবেন?

  2. Python Pandas - বহুপদী ইন্টারপোলেশন দিয়ে NaN পূরণ করুন

  3. Python Pandas - লিনিয়ার ইন্টারপোলেশন দিয়ে NaN পূরণ করুন

  4. পাইথন - একটি ডেটাফ্রেমের মান পান্ডাসে অন্য ডেটাফ্রেমের মান দিয়ে প্রতিস্থাপন করুন