Here’s the tutorial on how to print a row in Pandas.
This post will teach you how to print the row you need and which Pandas function can be used to print the row by the index number.
How to print chosen row in Pandas
Let’s assume you’d like to print the third row. How would you do that?
To print a row by index use loc Pandas function. Chosen row will be printed after using such a Python code:
print(df.iloc[[index]])
To print the second row put the index of 2.
import pandas as pd my_df = pd.DataFrame( {'Column1': ['1', '4', '3', '4'], 'Column2': ['5', '6', '2', '2'], 'Column3': ['33', '10', '43', '12']}) print(my_df.loc[[2]])
The output:
Column1 Column2 Column3 2 3 2 43
To get to know more check the loc function documentation.
How to print column names
How to print index