import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(2, 50, size=[3,4]), columns=list("ABCD"))
print(df)
"""
Output
A B C D
0 8 32 19 31
1 8 29 13 28
2 40 11 10 8
"""
# Fetching first row
print(df.iloc[0:1])
"""output
A B C D
0 8 32 19 31
"""
# Fetching last row
print(df.iloc[-1:])
"""
output
A B C D
2 40 11 10 8
"""
# Fetching first column
print(df.iloc[:,0])
"""
output
0 31
1 28
2 8
Name: D, dtype: int32
"""
#Fetching last column
print(df.iloc[:,-1])
"""
output
0 31
1 28
2 8
Name: D, dtype: int32
"""