Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk1 min

Print the First 10 Rows of a Pandas DataFrame in Python

Use df.head(10) to preview the first ten rows of a pandas DataFrame. In a script, print the result with print(df.head(10)).
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use df.head(10) to get the first ten rows of a pandas DataFrame. In a Python script, print the result with print(df.head(10)); in a notebook, enter df.head(10) in a cell to display it.

Print the first 10 rows

The head method returns a DataFrame containing rows from the beginning of the DataFrame’s current order. Pass 10 to request ten rows:

As an Amazon Associate I earn from qualifying purchases.

print(df.head(10))

For example:

import pandas as pd

df = pd.DataFrame({
    "name": ["Ava", "Ben", "Chen", "Dia", "Eli", "Fatima", "Gus", "Hana", "Ivan", "Jo"],
    "score": [91, 84, 88, 95, 79, 93, 86, 90, 82, 97],
})

print(df.head(10))

The result includes the existing index labels and columns; head does not reset the index.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What if the DataFrame has fewer than 10 rows?

df.head(10) returns every row that is available if the DataFrame contains fewer than ten. If it has no rows, the result is an empty DataFrame.

Why specify 10?

Calling df.head() without an argument returns five rows by default. Include 10 when you specifically want ten.

Does head(10) sort the data?

No. It selects rows by position from the current order; it neither sorts rows nor selects them by index label. To inspect the ten lowest values in a column, sort by that column or use a value-oriented method such as nsmallest.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Related ways to preview rows

  • df.tail(10) previews rows from the end.
  • df[:10] is equivalent to df.head(10) for a positive row count.

A preview only shows the beginning of the current data. It does not establish that every row is valid; for example, inspect dtypes when you need to check column data types.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

These behaviors are documented in the pandas 3.0.6 DataFrame.head reference and the pandas basics guide.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.