Products.csv file से data read करने और rows और columns की संख्या print करने के लिए Python program लिखें। फिर first ten rows के लिए 'product' column value 'Car' से match होने पर print करें।
मान लें, आपके पास 'products.csv' file है और rows और columns की संख्या और first ten rows के लिए 'product' column value 'Car' से match होने का result:
Products.csv file here download करें।
Rows: 100 Columns: 8 id product engine avgmileage price height_mm width_mm productionYear 1 2 Car Diesel 21 16500 1530 1735 2020 4 5 Car Gas 18 17450 1530 1780 2018 5 6 Car Gas 19 15250 1530 1790 2019 8 9 Car Diesel 23 16925 1530 1800 2018
इस problem के लिए हमारे पास दो अलग-अलग solutions हैं।
Solution 1
Products.csv file से data read करें और df assign करें
df = pd.read_csv('products.csv ')
Rows की संख्या = df.shape[0] और columns = df.shape[1] print करें
df1 set करें df से first ten rows filter करने के लिए iloc[0:10,:] का उपयोग करके
df1 = df.iloc[0:10,:]
Product column values matches to car calculate करें df1.iloc[:,1] का उपयोग करके
यहां, product column index 1 है और finally data print करें
df1[df1.iloc[:,1]=='Car']
उदाहरण
बेहतर समझ के लिए निम्न code check करें:
import pandas as pd
df = pd.read_csv('products.csv ')
print("Rows:", df.shape[0], "Columns:", df.shape[1])
df1 = df.iloc[0:10,:]
print(df1[df1.iloc[:,1]=='Car'])
आउटपुट
Rows: 100 Columns: 8 id product engine avgmileage price height_mm width_mm productionYear 1 2 Car Diesel 21 16500 1530 1735 2020 4 5 Car Gas 18 17450 1530 1780 2018 5 6 Car Gas 19 15250 1530 1790 2019 8 9 Car Diesel 23 16925 1530 1800 2018
Solution 2
Products.csv file से data read करें और df assign करें
df = pd.read_csv('products.csv ')
Rows की संख्या = df.shape[0] और columns = df.shape[1] print करें
df.head(10) का उपयोग करके first ten rows लें और df assign करें
df1 = df.head(10)
Product column values matches to Car लेने के लिए नीचे दी गई method का उपयोग करें
df1[df1['product']=='Car']
अब, आइए इसकी implementation check करें बेहतर समझ के लिए:
उदाहरण
import pandas as pd
df = pd.read_csv('products.csv ')
print("Rows:", df.shape[0], "Columns:", df.shape[1])
df1 = df.head(10)
print(df1[df1['product']=='Car'])
आउटपुट
Rows: 100 Columns: 8 id product engine avgmileage price height_mm width_mm productionYear 1 2 Car Diesel 21 16500 1530 1735 2020 4 5 Car Gas 18 17450 1530 1780 2018 5 6 Car Gas 19 15250 1530 1790 2019 8 9 Car Diesel 23 16925 1530 1800 2018