কম্পিউটার

Python Pandas - প্রথম ঘটনা ব্যতীত সদৃশ মান মুছে ফেলার সাথে রিটার্ন ইনডেক্স


প্রথম ঘটনা ব্যতীত সদৃশ মানগুলি সরানো সহ সূচক ফেরত দিতে, index.drop_duplicates() ব্যবহার করুন পদ্ধতি কিপ ব্যবহার করুন প্রথম মান সহ প্যারামিটার .

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

import pandas as pd

কিছু সদৃশ −

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

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

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

সদৃশ মান মুছে ফেলার সাথে রিটার্ন সূচক। "প্রথম" মান সহ "কিপ" প্যারামিটারটি সদৃশ এন্ট্রির প্রতিটি সেটের জন্য প্রথম ঘটনাটি রাখে -

index.drop_duplicates(keep='first')

উদাহরণ

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

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 bytes in the data
print("\nGet the bytes...\n",index.nbytes)

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

# Return Index with duplicate values removed
# The "keep" parameter with value "first" keeps the first occurrence for each set of duplicated entries
print("\nIndex with duplicate values removed (keeping the first occurrence)...\n",index.drop_duplicates(keep='first'))

আউটপুট

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

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

The dtype object...
object

Get the bytes...
40

Get the dimensions...
1

Index with duplicate values removed (keeping the first occurrence)...
Index(['Car', 'Bike', 'Airplane', 'Ship'], dtype='object')

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

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

  3. Python - পান্ডাস সূচকের সর্বোচ্চ মান ফেরত দিন

  4. পাইথন - পান্ডাস সূচকের সর্বনিম্ন মান ফেরত দিন