Interview Q&A / Data Science

INTERVIEW Q&A · 56 QUESTIONS

Data Science interview questions

Statistics, pandas, cleaning data and exploratory analysis for analyst and data science roles.

  1. What is the difference between merge, join and concat in pandas?

    merge combines two DataFrames on matching column values, like a SQL join. join does the same but matches on the index by default. concat simply stacks DataFrames on top of each other (rows) or side by side (columns) without matching any keys.

    BeginnerIn-depth3 min read
  2. How do you handle missing values in a dataset?

    First find how much is missing and why. Then either drop rows or columns (when little is missing or a column is mostly empty) or fill the gaps, using the median for skewed numbers, the mode for categories, forward fill for time series, or a model-based method. Often add a flag column that records which values were missing.

    IntermediateIn-depth4 min read
  3. How do you find and handle missing values in pandas?

    Use isna().sum() to count them, then dropna to remove rows or columns, or fillna to fill them with a constant, mean, median or group value. Check what share is missing first, since the right fix depends on it.

    BeginnerQuick answer1 min read
  4. How does groupby work in pandas?

    groupby splits the rows into groups by key, applies a function such as sum or count to each group, and combines the results into a new object. Named aggregation lets you compute several summaries in one call.

    BeginnerQuick answer1 min read
  5. What is the difference between loc and iloc in pandas?

    loc selects by label (index values and column names) and includes the end of a slice. iloc selects by integer position and excludes the end, like normal Python slicing.

    BeginnerQuick answer1 min read
  6. When would you use pivot_table instead of groupby in pandas?

    pivot_table is groupby with the second key spread across columns, giving a cross-tab style summary. Use it when you want a grid for reading or charting, and groupby when you want a long list of groups.

    BeginnerQuick answer1 min read
  7. How do you find rows in one DataFrame that have no match in another?

    Use a left merge with indicator=True and keep rows marked left_only, or filter with ~isin on the key column. This is the pandas version of a SQL anti-join, useful for finding missing records.

    IntermediateQuick answer1 min read
  8. What is the difference between agg and transform in a pandas groupby?

    agg returns one row per group, shrinking the data. transform returns a result with the same length as the original, repeating each group value on every row, so you can add it as a column and do row-level calculations like shares.

    IntermediateQuick answer1 min read
  9. Why is apply slower than vectorised operations in pandas?

    apply runs a Python function once per row or element, paying Python overhead each time. Vectorised operations such as column arithmetic or str methods run in compiled code on whole arrays, and are often tens of times faster.

    IntermediateQuick answer1 min read