print the 12 th row and the 13rd to 16th columns of the dataframe in python

You can use pandas iloc to select rows and columns by index. Here's an example that selects the 12th row and the 13th to 16th columns of a dataframe df:

main.py
import pandas as pd

# select the 12th row and the 13th to 16th columns
subset_df = df.iloc[11, 12:16]

# print the subset dataframe
print(subset_df)
150 chars
8 lines

Note that pandas uses zero-based indexing, so the 12th row has an index of 11. Also, when using iloc, the range of columns is inclusive of the first index and exclusive of the second index, so 12:16 selects the 13th to 16th column.

related categories

gistlibby LogSnag