How to Check the First and Last Rows of a Data Frame in Pandas (Python)

Channel:
Subscribers:
44,100
Published on ● Video Link: https://www.youtube.com/watch?v=r5JcWGIfgBg



Category:
Guide
Duration: 1:40
2,223 views
27


↓ Code Available Below! ↓

This video shows how to check the first and last rows of pandas data frame using the both the built in head and tail functions as well as index slicing with iloc. Checking the head and tail of a data frame is a common operation to get a sense of what your data looks like and avoid printing too many rows to the console. It is also a quick way of getting the top n results from a sorted data frame.

If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1


Code used in this Python Code Clip:

import pandas as pd

import statsmodels.api as sm #(To access mtcars dataset)
mtcars = sm.datasets.get_rdataset("mtcars", "datasets", cache=True).data

# Check the first n rows with df.head(n)
# Equivalent to df.iloc[0:n]

mtcars.head(6)

# Check the last n rows with df.tail(n)
# Equivalent to df.iloc[len(df)-n:len(df)]

mtcars.tail(6)


* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .


⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only







Tags:
pandas head
pandas tail
pandas .head()
pandas .tail()
tail()
head()
head
tail
data frame head
data frame tail
.head()
.tail()
get the first rows of a data frame
get the last rows of a data frame
data frame basics
data exploration basics
view data frame
pandas basics
learn pandas
top n
bottom n
check first rows of a data frame
check the last rows of a data frame
pandas data frame operations