19 May 2023

pandas.DataFrame.iloc

DataFrame.iloc allows you to select rows and columns using integer-based indexing. You can pass it an integer, a list of integers, a boolean array or a function.

Examples

mydict = [{'a': 1, 'b': 2},
                    {'a': 100, 'b': 200}]

df = pd.DataFrame(mydict)

# Output: 
#       a     b
# 0     1     2
# 1   100   200
df.iloc[0]

# Output: 
# a    1
# b    2
df.iloc[[True, False]]
#       a     b
# 0     1     2