How to select the last observation of a DataFrame
• 0 minKnowing how to select the last observations of a DataFrame might come in handy when you are doing some data exploration.
Using the DataFrame.tail() method will select the last observations, 5 by default.
Selecting the last observations
import pandas as pd
# We read a sample dataset from the web.
df = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
print(df.head())
Selecting the last 3 observations
import pandas as pd
# We read a sample dataset from the web.
df = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
print(df.head(3))
Here you are ! You now know how to select the top n observations of a DataFrame.