Black Friday Sale20% off every plan — this weekend onlyEnds in04days11hrs51min49secSee plans

Python pandas interview questions for data analysts

Python Updated 2 min read By LogicByte team

Short answer

Pandas questions in analyst interviews focus on selecting data (loc and iloc), cleaning (missing values, duplicates, types), combining tables (merge and concat), and summarising (groupby, pivot_table). Below are the common ones with code you can run.

On this page
  1. Selecting and filtering
  2. Cleaning
  3. Combining tables
  4. Summarising

Selecting and filtering

1. loc vs iloc

loc selects by label, iloc by position.

df.loc[df["city"] == "Pune", ["name", "salary"]]
df.iloc[0:5, 0:2]   # first five rows, first two columns

2. Filter with several conditions

df[(df["salary"] > 50000) & (df["dept"] == "Sales")]

Use & and |, not and / or, and wrap each condition in brackets.

Cleaning

3. Find and handle missing values

df.isna().sum()                 # missing per column
df["salary"] = df["salary"].fillna(df["salary"].median())
df = df.dropna(subset=["email"])

4. Remove duplicates

df = df.drop_duplicates(subset=["email"], keep="first")

5. Change a column's type

df["order_date"] = pd.to_datetime(df["order_date"])
df["amount"] = pd.to_numeric(df["amount"], errors="coerce")

Combining tables

6. merge vs concat

merge joins on a key like SQL; concat stacks DataFrames on top of (or beside) each other.

orders.merge(customers, on="customer_id", how="left")
pd.concat([jan, feb], ignore_index=True)

Summarising

7. groupby with several aggregates

df.groupby("dept").agg(staff=("id", "count"), avg_salary=("salary", "mean"))

8. pivot_table

df.pivot_table(index="region", columns="month", values="sales", aggfunc="sum", fill_value=0)

9. apply vs vectorised operations

apply runs a Python function row by row and is slow on large data. Prefer built-in column operations such as df["a"] * df["b"] or np.where.

10. Top 3 rows per group

df.sort_values("sales", ascending=False).groupby("region").head(3)

Try it yourself

5 questions from the LogicByte practice bank. Pick an answer to check it.

  1. 1What is the Global Interpreter Lock associated with in CPython?

    Show answer

    Answer: D — A lock that limits simultaneous execution of Python bytecode threads

    The GIL in standard CPython limits concurrent bytecode execution by threads.

  2. 2Which block handles an exception?

    Show answer

    Answer: D — except

    except handles exceptions raised in the try block.

  3. 3Which keyword is used to handle an exception after a try block?

    Show answer

    Answer: B — except

    except defines a handler for exceptions raised inside the try block.

  4. 4What is the Global Interpreter Lock associated with in CPython?

    Show answer

    Answer: C — A lock that limits simultaneous execution of Python bytecode threads

    The GIL in standard CPython limits concurrent bytecode execution by threads.

  5. 5What is the Global Interpreter Lock associated with in CPython?

    Show answer

    Answer: D — A lock that limits simultaneous execution of Python bytecode threads

    The GIL in standard CPython limits concurrent bytecode execution by threads.

Take the free 10-question Python test

Frequently asked questions

How much Python is needed for a data analyst role?

Usually pandas for cleaning and summarising, basic plotting, and enough core Python (lists, dictionaries, functions, loops) to read and write short scripts.

Is pandas asked in fresher interviews?

Often, for roles that list Python. Expect filtering, groupby, merge and handling missing values.

What is the difference between a Series and a DataFrame?

A Series is one column with an index. A DataFrame is a table of several Series that share the same index.