We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Inspect Head

Never start manipulating data without inspecting it first. In the real world, data gets messy. Inspection reveals:

  • Missing values that could break your analysis
  • Wrong data types (e.g., numbers stored as text)
  • Unexpected values (negative prices, dates far in the future)
  • Inconsistent column names

Skipping inspection leads to bugs that are hard to track down later.

The .head() method is straightforward: it returns a new DataFrame with just the first few rows. Use this to get a quick look at your data's shape, to see if it even makes sense.

head_df = df.head()  # Returns the first 5 rows (default setting)
print(head_df)

Which prints something like this:

         dish  price        ordered_at
0   Carbonara   16.5  2024-03-02 18:30
1  Margherita   12.0  2024-03-02 18:45
2    Tiramisu    7.5  2024-03-02 19:00
3  Bruschetta    6.0  2024-03-02 19:15
4     Negroni   11.0  2024-03-02 19:30

You can optionally pass a number to .head() to get a different number of rows:

df.head(10)  # Returns the first 10 rows

Assignment

SnackStack's operations team sometimes needs a quick sample of incoming sensor data before processing a full batch. Complete the preview_devices function. It accepts a DataFrame and a row count n, and returns the first n rows with only the "device_id" and "temperature" columns.