সূচক মান প্রতিস্থাপন করতে যেখানে শর্তটি মিথ্যা, ব্যবহার করুন index.isin() পান্ডাসে পদ্ধতি। প্রথমে, প্রয়োজনীয় লাইব্রেরিগুলি আমদানি করুন -
import pandas as pd
পান্ডাস সূচক তৈরি করা হচ্ছে -
index = pd.Index(['Electronics','Accessories','Decor', 'Books', 'Toys'], name ='Products')
পান্ডাস সূচক প্রদর্শন করুন -
print("Pandas Index...\n",index) মান প্রতিস্থাপন করুন যেখানে শর্ত False হয়। এখানে, 'সজ্জা' বাদে, অন্য প্রতিটি উপাদান প্রতিস্থাপিত হয় -
print("\nReplace index vales where condition is False...\n",index.where(index.isin(['Decor']), 'Miscellaneous')) উদাহরণ
নিম্নলিখিত কোড -
import pandas as pd
# Creating Pandas index
index = pd.Index(['Electronics','Accessories','Decor', 'Books', 'Toys'], name ='Products')
# 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)
# replace values where condition is False
# Here, except the 'Decor', every other element gets replaced
print("\nReplace index vales where condition is False...\n",index.where(index.isin(['Decor']), 'Miscellaneous')) আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেPandas Index... Index(['Electronics', 'Accessories', 'Decor', 'Books', 'Toys'], dtype='object', name='Products') Number of elements in the index... 5 The dtype object... object Replace index vales where condition is False... Index(['Miscellaneous', 'Miscellaneous', 'Decor', 'Miscellaneous','Miscellaneous'],dtype='object', name='Products')