हम डेटाफ्रेम में किसी विशिष्ट मान को खोज सकते हैं। आवश्यक मान प्राप्त करने और पूरी पंक्ति प्रदर्शित करने के लिए iloc का उपयोग करें। सबसे पहले आवश्यक लाइब्रेरी इम्पोर्ट करें –
import pandas as pd
4 कॉलम वाला डेटाफ्रेम बनाएं –
dataFrame = pd.DataFrame({"Car": ['BMW', 'Lexus', 'Tesla', 'Mustang', 'Mercedes', 'Jaguar'],"Cubic_Capacity": [2000, 1800, 1500, 2500, 2200, 3000],"Reg_Price": [7000, 1500, 5000, 8000, 9000, 6000],"Units_Sold": [100, 120, 150, 110, 200, 250] })
आइए रजिस्ट्रेशन प्राइस 5000 वाली कार खोजें –
for i in range(len(dataFrame.Car)):
if 5000 == dataFrame.Reg_Price[i]:
indx = i
अब, मिला हुआ मान प्रदर्शित करें –
dataFrame.iloc[indx]
उदाहरण
निम्न कोड है –
import pandas as pd
# डेटाफ्रेम बनाना
dataFrame = pd.DataFrame({"Car": ['BMW', 'Lexus', 'Tesla', 'Mustang', 'Mercedes', 'Jaguar'],"Cubic_Capacity": [2000, 1800, 1500, 2500, 2200, 3000],"Reg_Price": [7000, 1500, 5000, 8000, 9000, 6000],"Units_Sold": [100, 120, 150, 110, 200, 250] })
print "DataFrame ...\n", dataFrame
# रजिस्ट्रेशन प्राइस 5000 वाली कार खोजें
for i in range(len(dataFrame.Car)):
if 5000 == dataFrame.Reg_Price[i]:
indx = i
# मिला हुआ मान प्रदर्शित करें
print "\nSearched DataFrame for the following specific value...\n", dataFrame.iloc[indx]
आउटपुट
यह निम्न आउटपुट उत्पन्न करेगा –
DataFrame ... Car Cubic_Capacity Reg_Price Units_Sold 0 BMW 2000 7000 100 1 Lexus 1800 1500 120 2 Tesla 1500 5000 150 3 Mustang 2500 8000 110 4 Mercedes 2200 9000 200 5 Jaguar 3000 6000 250 Searched DataFrame for the following specific value... Car Tesla Cubic_Capacity 1500 Reg_Price 5000 Units_Sold 150 Name: 2, dtype: object