Sub topic 1
What a First Exploratory Analysis Is For
What exploration is for
Exploratory data analysis (EDA) is the first structured pass through an unfamiliar dataset. It helps you learn what the columns mean, whether values are missing or invalid, and which questions are worth testing.
EDA is not a final statistical analysis. It reveals patterns and problems. It does not prove that one variable causes another. Record observations together with their limits, such as missing values or very small groups.
DataFrames and Series in a nutshell
A pandas DataFrame is a labeled table with rows and columns. A pandas Series is one labeled column from that table. Each column has a data type, such as integer, decimal, or text.
Prerequisites
You should know basic Python variables, lists, dictionaries, and functions. You also need pandas installed and a way to run a notebook or Python script.
Loading the Titanic CSV
A CSV (comma-separated values) file stores table data as text. Load it with pd.read_csv. The result is a DataFrame. Here, train.csv is the Titanic training file, with columns such as Survived, Pclass, Sex, Age, and Fare.
import pandas as pd
df = pd.read_csv("train.csv")
print(df.shape)The variable df is only a name. Choose a name that makes the dataset clear in a larger project.
Taking a first look
Start with size, sample rows, and structure. shape returns (rows, columns). head displays sample records. info reports column names, data types, and non-null counts. A non-null count is the number of values that are present.
print("shape:", df.shape)
print(df.head())
df.info()
print(df.dtypes)This first look can expose unexpected column names, numeric values stored as text, or columns with many absent values. It also gives you the denominator needed to interpret later counts.
Finding and understanding missing values
A missing value means that a field has no recorded value. Missingness may reflect an unavailable measurement, a question that did not apply, or a data-entry problem. Do not assume that every missing value means zero.
missing = pd.DataFrame({
"count": df.isna().sum(),
"percent": (df.isna().mean() * 100).round(1),
})
print(missing[missing["count"] > 0].sort_values("count", ascending=False))Use both the count and percentage. A column missing 20 values may be minor in a million-row dataset but serious in a 30-row dataset. Later chapters can decide whether to remove, fill, or model missing values.
Exercise
What does a non-null count of 714 mean for a column in a DataFrame with 891 rows?
Show answer
The column has 714 present values and 177 missing values.