Python for data analysis: pandas basics
Most pandas tutorials start with a dataset that's already clean, which skips the part that takes the most time in practice. This one starts with a CSV that has the kind of problems real data actually has.
Loading data
import pandas as pd
df = pd.read_csv('signups.csv')
print(df.head())
print(df.shape)
df.head() shows the first five rows so you can eyeball the structure; df.shape gives you (rows, columns) so you know how much data you're working with before doing anything else.
Finding what's wrong with it
Real datasets have missing values, inconsistent types, and duplicate rows. Check for all three before analyzing anything:
df.isna().sum()
df.dtypes
df.duplicated().sum()
isna().sum() counts missing values per column — if signup_date shows 40 missing out of 2,000 rows, you now know exactly how much of your data would silently vanish from a date-based analysis.
Cleaning it up
df = df.drop_duplicates()
df['signup_date'] = pd.to_datetime(df['signup_date'], errors='coerce')
df = df.dropna(subset=['signup_date'])
errors='coerce' turns unparseable dates into NaT instead of crashing the whole conversion — which is exactly why the dropna step after it exists, to remove the rows that couldn't be parsed at all.
Dropping rows with dropna() before you've checked how many rows that affects can quietly delete a large chunk of your dataset. Always run isna().sum() first so the number you're dropping is a decision, not a surprise.
Asking a real question
With clean data, grouping and aggregating is where pandas earns its reputation:
signups_by_month = (
df.groupby(df['signup_date'].dt.to_period('M'))
.size()
.rename('signups')
)
print(signups_by_month)
This groups every row by month and counts them — the same pattern works for sums, averages, or any other aggregation by swapping .size() for .sum() or .mean() on a specific column.
Where to go from here
Once grouping and filtering feel natural, df.plot() (backed by matplotlib) turns the same grouped data into a quick chart with almost no extra code — useful for a first look before reaching for a dedicated visualization library.