Skip to content
Case Study · Q3

Q.Display the first 10 rows of the DataFrame autodf. (Dataset: the UCI 'auto-mpg' open dataset — 398 rows, nine attributes: mpg, cylinders, displacement, horsepower, weight, acceleration, model year, origin, car name.)

Puducherry TnboardTextbookSubjective· 2mImportance★★★★★est
74% · 39/53 Questions
✓ Free question

autodf.head(10) returns the first 10 rows of the DataFrame — the standard way to sample the top of a dataset during initial exploration, before running any real analysis.

Why look at the first rows at all?

Before you compute a single statistic, you inspect the data: are the column names what you expect, do the values look like the right kind of number, is anything obviously broken (wrong units, text where you expected numbers, all-zero columns)? head(n) is the fastest way to do that — it prints the top n rows without scanning or summarizing the whole DataFrame, so it's cheap even on a dataset far bigger than 398 rows.

import pandas as pd

# Assuming autodf is already loaded
autodf.head(10)

Output:

mpgcylindersdisplacementhorsepowerweightaccelerationmodel_yearorigincar_name
018.08307.0130.0350412.0701chevrolet chevelle malibu
115.08350.0165.0369311.5701buick skylark 320
218.08318.0150.0343611.0701plymouth satellite
316.08304.0150.0343312.0701amc rebel sst
417.08302.0140.0344910.5701ford torino
515.08429.0198.0434110.0701ford galaxie 500
614.08454.0220.043549.0701chevrolet impala
714.08440.0215.043128.5701plymouth fury iii
814.08455.0225.0442510.0701pontiac catalina
915.08390.0190.038508.5701amc ambassador dpl

Reading what the output tells you

Even before running any statistics, this preview already tells a story:

  • model_year is 70 for all ten rows — the dataset is loaded in chronological order, so its earliest records are all from 1970 (stored as the two-digit code 70, not 1970).
  • cylinders is 8 and origin is 1 for every one of these rows — every early car is a large-engine, American-made (origin == 1) model. This is a real, visible pattern in the printed rows, not a coincidence of a random sample: if you only ever looked at head(), you would wrongly conclude the whole dataset is 8-cylinder American cars. Fuel-efficient 4-cylinder and non-US cars (origin 2 = Europe, 3 = Japan) appear later, as model years progress — which is exactly why head() is a sanity check, not a substitute for looking at the full distribution (e.g. autodf['cylinders'].value_counts() or autodf['origin'].value_counts()).
  • mpg in this early slice ranges from 14.0 to 18.0 — comparatively low, consistent with the large-displacement engines shown in the same rows. That relationship (bigger engine → lower mpg) is one of the first things this dataset is normally used to illustrate.

head() vs. related methods

MethodWhat it returns
autodf.head(10)first 10 rows, in file/index order
autodf.tail(10)last 10 rows, in file/index order
autodf.sample(10)10 randomly chosen rows (different every call unless you set random_state)
autodf[:10]equivalent to head(10) via positional slicing

head()/tail() are deterministic and index-order-based, which is why they're the right tool for "does this look like it loaded correctly?" — sample() is the better tool once you want an unbiased look at the dataset as a whole, precisely because (as above) the first 10 rows alone are not representative of the full 398.

Tip

If you want to see the last nn rows instead, use autodf.tail(n). Both methods return a new DataFrame slice without modifying the original — they never mutate autodf.

✓Final answer

autodf.head(10) displays the first 10 rows of the DataFrame — all nine columns (mpg, cylinders, displacement, horsepower, weight, acceleration, model_year, origin, car_name). In this dataset those first 10 records are all 1970-model, 8-cylinder, American-made (origin=1) cars with correspondingly low mpg — illustrating why head() is useful for a quick sanity check, but not a substitute for examining the dataset's full range with methods like .describe() or .value_counts().

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.