You can access rows in pandas DataFrame using the .iloc method. The .iloc method is an indexer that allows you to select rows and columns by their integer positions.
For example, to access the first row of a DataFrame you would use the following code:
main.py133 chars8 lines
This code creates a new DataFrame using the pd.DataFrame method, and selects the first row of the DataFrame using the .iloc method. The resulting output should be:
main.py49 chars4 lines
Here, Column1 and Column2 are the names of the columns in the DataFrame, 1 and A are the values of the first row.
You can also select multiple rows with a single command:
main.py143 chars8 lines
This code selects the rows from position 0 to position 1 (excluding position 2) and prints them out.
main.py57 chars4 lines
gistlibby LogSnag