সারি এবং কলামের একটি উপসেট নির্বাচন করতে, loc ব্যবহার করুন . সূচী অপারেটর ব্যবহার করুন অর্থাৎ বর্গাকার বন্ধনী এবং অবস্থানে শর্ত সেট করুন।
ধরা যাক মাইক্রোসফ্ট এক্সেল -
-এ খোলা আমাদের CSV ফাইলের বিষয়বস্তু নিম্নরূপ

প্রথমে, একটি CSV ফাইল থেকে একটি পান্ডাস ডেটাফ্রেম -
-এ ডেটা লোড করুন৷dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\SalesData.csv") একত্রিত সারি এবং কলামগুলির একটি উপসেট নির্বাচন করুন। ডান কলাম আপনি যে কলামটি প্রদর্শন করতে চান তা প্রদর্শন করে যেমন গাড়ির কলাম এখানে −
dataFrame.loc[dataFrame["Units"] > 100, "Car"]
উদাহরণ
নিম্নলিখিত কোড -
import pandas as pd
# Load data from a CSV file into a Pandas DataFrame:
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\SalesData.csv")
print("\nReading the CSV file...\n",dataFrame)
# selecting a subset of rows
print("\nSelect cars with Units more than 100: \n",dataFrame[dataFrame["Units"] > 100])
# displaying only two columns
res = dataFrame[['Reg_Price','Units']];
print("\nDisplaying only two columns : \n",res)
# Select a subset of rows and columns combined
# Right column displays the column you want to display i.e. Cars column here
res2 = dataFrame.loc[dataFrame["Units"] > 100, "Car"]
# display subset
print("\nSubset...\n",res2) আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেReading the CSV file... Car Reg_Price Units 0 BMW 2500 100 1 Lexus 3500 80 2 Audi 2500 120 3 Jaguar 2000 70 4 Mustang 2500 110 Select cars with Units more than 100: Car Reg_Price Units 2 Audi 2500 120 4 Mustang 2500 110 Displaying only two columns : Reg_Price Units 0 2500 100 1 3500 80 2 2500 120 3 2000 70 4 2500 110 Subset... 2 Audi 4 Mustang Name: Car, dtype: object