Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 6/ 160
01. Python & Data Wrangling

Pandas Series & DataFrames

Load tabular data into Series/DataFrames and inspect shape, dtypes, and summary stats.

BeginnerSeries · DataFrame · Inspect3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

A DataFrame is a table with named columns; you check its size, first rows and column types before doing anything else.

Think of it like…

Opening a new spreadsheet someone emailed you: before using it you check how many rows and columns there are, scan the first few lines, look at each column's type and see whether anything looks strange. The DataFrame methods do exactly that, but programmatically.

Where you’ve seen it

An analyst loads orders.csv (1.2 million rows). df.info() shows order_date is object (text), customer_id is float64 because of a few missing values, and amount has 1.2M non-null of 1.2M while coupon has only 180K non-null. Those three lines of output set the cleaning plan: parse dates, convert IDs to nullable integers, and treat missing coupons as "no coupon".

Words you’ll hear

Series / DataFrame
A labelled 1-D array / a 2-D table of Series sharing an index.
Index
The row labels; can be integers, strings or dates and is used for alignment.
dtype
A column's type: int64, float64, object/string, bool, datetime64, category.
info() / describe()
Structure and memory / summary statistics of the data.

Visual diagram

Loading interactive diagram

Theory & deep dive

Series, DataFrames and the index

A DataFrame is built from a dict of columns (pd.DataFrame({"city": [...], "sales": [...]})), from files (read_csv, read_parquet, read_excel) or from queries (read_sql). Each column is a Series: df["sales"] returns one, while df[["city", "sales"]] returns a DataFrame. The index labels rows and drives alignment, so adding two Series matches by label, not position, and a label missing on one side becomes NaN.

Useful attributes are df.columns, df.dtypes, df.index and df.shape. Rename columns with df.rename(columns={...}) or normalise them (df.columns = df.columns.str.strip().str.lower().str.replace(" ", "_")) so later code is predictable. Use set_index when a column is a natural key or a time axis, and reset_index() to turn it back into a column.

Loading with types declared

df = pd.read_csv("orders.csv", dtype={"customer_id": "Int64", "status": "category"}, parse_dates=["order_date"]) fixes the common type problems at load time instead of after the fact.

Key takeaway: Columns are Series, the index aligns rows, and dtypes are best set at load.

Reading info() and describe()

df.info() lists each column with its non-null count and dtype, plus memory use. Compare non-null counts to the row count to see missing data at a glance, and look for object columns that should be numbers, dates or categories. df.describe() reports count, mean, std, min, quartiles and max for numeric columns; add include="all" for counts, unique values and top frequency of text columns. A max far above the 75th percentile, a negative minimum for a quantity, or a mean far from the median hints at outliers or data errors.

Quick follow-ups: df.isna().sum() for missing counts per column, df["col"].value_counts(dropna=False) for categories (including missing), df.nunique() for cardinality (a column with nunique equal to the row count is probably an ID), and df.duplicated().sum() for repeated rows. For wide frames set pd.set_option("display.max_columns", 100) so nothing is hidden. Treat these outputs as questions to ask the data owner, not just numbers.

Reading the output

amount min = -250 and max = 9,800,000 with a median of 1,150: negative amounts may be refunds, and the maximum is likely a data entry error or an enterprise order. Neither should be dropped or kept without checking.

Key takeaway: Compare non-null counts to rows, scan dtypes, and treat min/max surprises as questions.

How it works, step by step

Step 1 of 4
I/O

1. Load with sensible types

Read the file with known dtypes and date columns declared, using nullable types where missing values exist.

dtype={"customer_id": "Int64"}, parse_dates=["order_date"]
Key numbers at this step
Fixes
types at the source

When to use it & trade-offs

What it is

A Series is a one-dimensional labelled array (one column); a DataFrame is a table of Series that share a row index, each column with its own dtype. After loading data with pd.read_csv(...), a short inspection routine tells you what you have: df.shape, df.head(), df.info() (columns, dtypes, non-null counts, memory) and df.describe() (summary statistics). That first look catches most data problems before any analysis begins.

Why it matters: Every pandas workflow starts here, and mistakes at this stage are expensive later: numbers loaded as strings, dates left as text, IDs read as floats, or half a column missing. Knowing what info() and describe() do and don't show, such as describe() ignoring text columns by default, lets you spot issues in minutes.

When to reach for it

  • The first five minutes with any new dataset
  • Spotting wrongly typed columns
  • Deciding which columns need cleaning

When to avoid or be careful

  • Modelling before checking dtypes and missing counts
  • Reading CSV IDs as floats because of a few NaNs
  • Assuming describe() covers text columns

Inspection tools

df.info()
Best for: Types, non-null counts and memory

Strengths: Shows structure at a glance.

Watch out: Says nothing about value ranges.

df.describe()
Best for: Ranges, spread and outlier hints

Strengths: Quick numeric summary.

Watch out: Numeric columns only by default; hides distributions.

Profiling reports (ydata-profiling)
Best for: Wide datasets needing a thorough first pass

Strengths: Automated summaries, correlations, missing patterns.

Watch out: Slow on big data; still needs human judgement.

Interview signals & numbers to know

When this topic comes up

  • “What would you do first with a new dataset?”
  • “Why is this numeric column an object?”
  • “How many missing values per column?”
  • DataFrame basics
  • Data profiling

Benchmarks & rules of thumb

5 calls -
shape, head, info, describe, isna().sum()
object -
dtype that usually needs attention
max vs 75th percentile -
a quick outlier check

Common mistakes & follow-ups

Common interview mistakes

  • Loading IDs as float64, then losing leading zeros or precision.
  • Reading describe() output and forgetting text and date columns weren't included.
  • Silently dropping negative amounts that were valid refunds.

Likely interviewer follow-ups

  • What do you check right after loading a CSV?
  • How can you tell a column is probably an ID?
  • Why might a numeric column load as object?
Interview tip: Describe your first-look routine as a repeatable checklist (shape, head, info, describe, missing counts). Interviewers read it as process maturity.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Pandas Series & DataFrames with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Broadcasting & Linear Algebra Ops
Next topic
Indexing, Slicing & Filtering