Creating DataFrame to Select a Row by Index
Here, we are creating a Pandas Dataframe with ID, Product, Price, Color, and Discount with there some values in it.
Python3
# import pandas library import pandas as pd # Create the dataframe df = pd.DataFrame({ 'ID' : [ '114' , '345' , '157788' , '5626' ], 'Product' : [ 'shirt' , 'trousers' , 'tie' , 'belt' ], 'Price' : [ 1200 , 1500 , 600 , 352 ], 'Color' : [ 'White' , 'Black' , 'Red' , 'Brown' ], 'Discount' : [ 10 , 10 , 10 , 10 ]}) # Show the dataframe df |
Output:
Select a row of series or dataframe by given integer index
The Dataframe.iloc[] is used to select a row of Series/Dataframe by a given integer index in Python.