A complete first data exploration
Create a Python project that loads, inspects, cleans and summarizes customer data. You will understand what the dataset contains before using it for Ai.
Load, inspect, clean and summarize a small customer dataset before building your first Ai model.
Create a Python project that loads, inspects, cleans and summarizes customer data. You will understand what the dataset contains before using it for Ai.
project-02-python-data-explorer/
├── data/customer-data.csv
├── notebooks/data-explorer.ipynb
├── outputs/data-summary.txt
├── README.md
└── requirements.txtRun each code block, confirm its output, then mark the step complete.
Prepare pandas for data work and matplotlib for the chart.
pip install pandas matplotlibpandas
matplotlibRead the CSV file and handle a missing-file error clearly.
import pandas as pd
file_path = "data/customer-data.csv"
try:
df = pd.read_csv(file_path)
print("Dataset loaded successfully.")
except FileNotFoundError:
print(f"Dataset not found: {file_path}")Dataset loaded successfully.
Understand its size, columns, values and data types.
print(df.head())
print(df.shape)
print(df.columns)
df.info()Find missing values and duplicates before changing the data.
print("Missing values:")
print(df.isnull().sum())
print("\nDuplicate rows:")
print(df.duplicated().sum())df = df.drop_duplicates()
df["Monthly Spending"] = df["Monthly Spending"].fillna(
df["Monthly Spending"].median()
)Replace each column name with the exact name used in your dataset. Check why a row is duplicated before removing it.
Calculate useful numerical and category summaries.
print(df.describe())
average_spending = df["Monthly Spending"].mean()
average_purchases = df["Number of Purchases"].mean()
print("Average monthly spending:", round(average_spending, 2))
print("Average number of purchases:", round(average_purchases, 2))
print(df["Membership Type"].value_counts())Find high-spending customers and compare membership groups.
high_spending_customers = df[df["Monthly Spending"] > 100]
print(high_spending_customers.head())
membership_summary = (
df.groupby("Membership Type")["Monthly Spending"]
.mean()
.sort_values(ascending=False)
)
print(membership_summary)Visualise average spending across membership groups.
import matplotlib.pyplot as plt
membership_summary.plot(kind="bar")
plt.title("Average Spending by Membership Type")
plt.xlabel("Membership Type")
plt.ylabel("Average Monthly Spending")
plt.tight_layout()
plt.show()A bar chart comparing average spending across membership groups.
I created a Python Data Explorer using pandas. I loaded and inspected a customer dataset, checked data types, handled missing values, removed duplicates, calculated summary statistics and created a chart comparing customer groups. This project developed my basic Python, data-cleaning and exploratory-analysis skills.