पंक्तियों और स्तंभों का एक सबसेट चुनने के लिए, स्थान . का उपयोग करें . इंडेक्स ऑपरेटर यानी वर्गाकार ब्रैकेट का इस्तेमाल करें और इलाके में शर्तें तय करें.
मान लें कि Microsoft Excel में खोली गई हमारी 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