কম্পিউটার

Python Pandas - শেষ ঘটনা ব্যতীত ডুপ্লিকেট সূচক মান নির্দেশ করে


শেষ ঘটনা ব্যতীত ডুপ্লিকেট সূচক মান নির্দেশ করতে, index.duplicated() ব্যবহার করুন . কিপ ব্যবহার করুন শেষের মান সহ প্যারামিটার .

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

import pandas as pd

কিছু সদৃশ-

দিয়ে সূচক তৈরি করা হচ্ছে
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])

সূচক প্রদর্শন করুন -

print("Pandas Index with duplicates...\n",index)

ডুপ্লিকেট সূচক মানগুলিকে সত্য হিসাবে নির্দেশ করুন, শেষ ঘটনাটি ছাড়া। "কিপ" প্যারামিটারটিকে "শেষ" হিসাবে সেট করুন -

print("\nIndicating duplicate values except the last occurrence...\n", index.duplicated(keep='last'))

উদাহরণ

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

import pandas as pd

# Creating the index with some duplicates
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])

# Display the index
print("Pandas Index with duplicates...\n",index)

# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)

# get the dimensions of the data
print("\nGet the dimensions...\n",index.ndim)

# Indicate duplicate index values as True, except the last occurrence
# Set the "keep" parameter as "last"
print("\nIndicating duplicate values except the last occurrence...\n", index.duplicated(keep='last'))

আউটপুট

এটি নিম্নলিখিত কোড তৈরি করবে -

Pandas Index with duplicates...
Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane'], dtype='object')

The dtype object...
object

Get the dimensions...
1

Indicating duplicate values except the last occurrence...
[False False True False False]

  1. Python Pandas - সূচকে অনন্য মান ফেরত দিন

  2. Python Pandas - সূচক দ্বারা নির্বাচিত মানগুলির একটি নতুন সূচক ফেরত দিন

  3. Python Pandas - সূচী মান প্রতিস্থাপন করুন যেখানে শর্তটি মিথ্যা

  4. Python Pandas - একটি উপসেট তৈরি করুন এবং শুধুমাত্র ডুপ্লিকেট মান থেকে শেষ এন্ট্রি প্রদর্শন করুন