If a job description mentions Python, expect pandas questions. They are usually practical: "given this DataFrame, how would you…". Here are the questions that come up most, with answers.
Basics
Series vs DataFrame
A Series is a single labelled column of values. A DataFrame is a table: a collection of Series sharing the same index.
loc vs iloc
loc selects by label (index labels and column names); iloc selects by position (integer row and column numbers).
df.loc[df["city"] == "Pune", ["name", "amount"]]
df.iloc[0:5, 0:3]A detail interviewers like: loc slices include the end label; iloc slices exclude the end position.
How do you check data types and missing values?
df.info() for both; df.dtypes for types; df.isna().sum() for missing counts per column.
Cleaning
How do you handle missing values?
First understand why they are missing. Then choose: drop rows (dropna) if few and random, fill with a sensible value (fillna with median, mode, zero or a forward fill for time series), or keep them and flag them. Never fill blindly.
How do you remove duplicates?
df.drop_duplicates(), or df.drop_duplicates(subset=["order_id"], keep="last") to define what a duplicate means.
How do you change a column's type?
astype for simple cases; pd.to_datetime and pd.to_numeric(errors="coerce") for messy data, which turn bad values into NaT/NaN instead of failing.
Combining data
merge vs concat vs join
merge: SQL-style join on columns (how="inner" | "left" | "right" | "outer").concat: stacks DataFrames vertically (more rows) or side by side.join: a shortcut for merging on the index.
What happens if the key is duplicated in both tables?
Rows multiply: each match on one side pairs with each match on the other. Use validate="one_to_one" or "many_to_one" to catch this.
Aggregation
Group by city and get several summaries
df.groupby("city").agg(
orders=("order_id", "count"),
revenue=("amount", "sum"),
avg_amount=("amount", "mean"),
)groupby().transform vs agg
agg returns one row per group. transform returns a value for every original row, aligned to the original index, which is useful for "each row's share of its group total".
df["share_of_city"] = df["amount"] / df.groupby("city")["amount"].transform("sum")pivot vs pivot_table
pivot reshapes without aggregating and fails on duplicates; pivot_table aggregates duplicates with a function you choose.
Performance
apply vs vectorised operations
Vectorised operations (df["a"] * df["b"], np.where, .str methods) run on whole columns in optimised code and are much faster than apply with a Python function row by row. Use apply only when there is no vectorised alternative.
Practical tasks you may be given
- Top 3 products by revenue in each category: sort, then
groupby().head(3), or userank. - Month-on-month growth: resample or group by month, then
pct_change(). - Customers who ordered in January but not February: build two sets of IDs and take the difference, or use a merge with
indicator=True. - Fill missing values with the group median:
df["x"].fillna(df.groupby("g")["x"].transform("median")).
Practise
Work through our pandas track and finish with practice test 2, which mixes merges, dates and pivots the way interviews do.
Practise what you just read
Reading helps; writing the code yourself is what sticks. Start here: