BuildlyBuildly
DashboardExercisesProfileHelp
Data Science/Module 2: Data Analytics/Series & DataFrame2/3
Exercise·7 min·10 XP

First N Rows

Context. A preview helper — given a DataFrame and a count n, return only the first n rows.

Your task. Write first_n(df, n) that returns a DataFrame containing the first n rows of df, preserving the original column order.

Example. A 5-row df with n=2 → the first 2 rows as a DataFrame.

Notes. If n is larger than the number of rows, return all rows. If n is 0, return an empty DataFrame (same columns, no rows).

Previous
Shape and Column Names
Next
Parse a CSV String