মুছে ফেলা লেবেলগুলির পাস করা তালিকা সহ নতুন সূচক তৈরি করতে, index.drop() ব্যবহার করুন পদ্ধতি এতে লেবেলের তালিকা পাস করুন।
প্রথমে, প্রয়োজনীয় লাইব্রেরিগুলি আমদানি করুন -
import pandas as pd
সূচক তৈরি করা হচ্ছে -
index = pd.Index(['Car','Bike','Truck','Ship','Airplane'])
সূচক প্রদর্শন করুন -
print("Pandas Index...\n",index) ড্রপ করা লেবেল ধারণকারী একটি তালিকা পাস করা হয় -
print("\nUpdated index after deleting labels...\n",index.drop(['Bike', 'Ship']))
উদাহরণ
নিম্নলিখিত কোড -
import pandas as pd
# Creating the index
index = pd.Index(['Car','Bike','Truck','Ship','Airplane'])
# Display the index
print("Pandas Index...\n",index)
# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)
# Return a tuple of the shape of the underlying data
print("\nA tuple of the shape of underlying data...\n",index.shape)
# a list containing labels to be dropped are passed
print("\nUpdated index after deleting labels...\n",index.drop(['Bike', 'Ship'])) আউটপুট
এটি নিম্নলিখিত কোড তৈরি করবে -
Pandas Index... Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'], dtype='object') The dtype object... object A tuple of the shape of underlying data... (5,) Updated index after deleting labels... Index(['Car', 'Truck', 'Airplane'], dtype='object')