01.08 Lesson 8 of 10
48 minPandas: Load, Inspect & Select
Load a CSV into a DataFrame, inspect its schema and select the rows and columns you need.
By the end of this lesson
You will be able to
- Load a CSV with
read_csv. - Inspect rows, columns, dtypes and summary information.
- Select columns and filter rows.
- Create a derived column using vectorized expressions.
Load first, inspect before changing
Use read_csv to load the file, then inspect the first and last rows, shape, dtypes and missing-value counts. Do not begin cleaning before you understand what each column represents.
import pandas as pd
df = pd.read_csv("data/hour.csv")
print(df.head())
print(df.shape)
print(df.dtypes)
print(df.isna().sum()) Select columns and rows explicitly
Use bracket selection for columns, .loc for label-based selection and .iloc for position-based selection. Boolean masks make a filter readable. Prefer these explicit operations over chained indexing.
hour_and_count = df[["hr", "cnt"]]
working_hours = df.loc[df["workingday"] == 1, ["hr", "cnt"]]
first_five = df.iloc[:5]
df["total_check"] = df["casual"] + df["registered"] Apply what you learned
ExerciseInspect the Bike Sharing CSV
Load hour.csv and produce a compact first-look report before cleaning anything.
- Read the CSV with pandas.
- Record the exact row and column counts from your downloaded file.
- Print the schema and the first five rows.
- Select
hr,temp,humandcnt. - Filter working-day rows and compare their row count with the full dataset.
Your report distinguishes file facts from assumptions and includes the downloaded file name and a schema snapshot.
Free references
Study resources
- 01 Getting started tutorials Article
Use the tutorials for reading/writing data, selecting subsets and creating derived columns.
- 02 Getting Started with Data Analysis Video
Watch this single video for loading a CSV and inspecting its DataFrame.
Check your understanding
Self-test
-
Question 1
What does
df.shapereturn?A pair(rows, columns)describing the DataFrame dimensions. -
Question 2
When would you use
.locinstead of.iloc?Use.locfor labels or boolean conditions; use.ilocfor integer positions.
Completion check
Move on when
You can load a CSV, inspect its schema and make explicit selections and filters.