Skip to main content

Command Palette

Search for a command to run...

Using iloc to get the last row of a Pandas DataFrame

Published
1 min read
M

Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He is studying at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).

import pandas as pd

# Example DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

# Get the last row using iloc
last_row = df.iloc[-1]

print("Last row:")
print(last_row)

output: