Professional Documents
Culture Documents
df=pd.DataFrame({'Name':['Anil','Subhash','Simoni','Sneha','Dhruv','Anil'],
'Age':[12,14,15,16,13,16],
'Class':[10,11,12,11,9,10],
'Div':['vega','antares','rigel','deneb','vega','sirius'],
'house':['red','blue','yellow','blue','green','red']
})
print(df)
# loc() prints all the rows inclusive of the index specified
print(df.loc[2:4])
# iloc() prints from the row specifieds to the end-1 row
print(df.iloc[2:4])
# to print specific columns use []
print(df.loc[1:3,['Name','Class']])
# we cannot specify label with iloc[] but with loc we can
print(df.iloc[1:3,['Name','Class']])
use loc[]to print specific row and columns
print(df.loc[[1,3],['Name','Div']])
OUTPUT: