কম্পিউটার

Python Pandas - NaN মান বিবেচনা করে ইনডেক্স অবজেক্ট থেকে অনন্য মানের গণনা ধারণকারী একটি সিরিজ ফেরত দিন


সূচক অবজেক্ট থেকে NaN মান বিবেচনা করে index.value_counts() এর সাথে অনন্য মানের সংখ্যা সম্বলিত একটি সিরিজ ফেরত দিতে পদ্ধতি প্যারামিটার ড্রপনা সেট করুন মিথ্যা মান সহ .

প্রথমে, প্রয়োজনীয় লাইব্রেরি আমদানি করুন -

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)

value_count() ব্যবহার করে অনন্য মানের গণনা। "ড্রপনা" প্যারামিটারের "ফলস" মান ব্যবহার করার পাশাপাশি NaN বিবেচনা করা −

index.value_counts(dropna=False)

উদাহরণ

নিম্নলিখিত কোড -

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)

# count of unique values using value_counts()
# considering NaN as well using the "False" value of the "dropna" parameter
print("\nGet the count of unique values with NaN...\n",index.value_counts(dropna=False))

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
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

Get the count of unique values with NaN...
NaN   3
50.0  2
10.0  1
70.0  1
90.0  1
30.0  1
dtype: int64
দিয়ে অনন্য মান গণনা পান
  1. Python Pandas - Timedelta অবজেক্ট থেকে ন্যানোসেকেন্ড ফেরত দিন

  2. Python Pandas - Timedelta অবজেক্ট থেকে মাইক্রোসেকেন্ড রিটার্ন করুন

  3. Python Pandas - একটি একক কলাম থেকে অনন্য মান খুঁজুন

  4. Python Pandas - একটি কলাম থেকে অনন্য মান পান