Python interview questions for data analystsTechnical interview questions
← Interview & exam prep
Technical interview questions

Python interview questions for data analysts

22 questions from beginner to advanced, each with the correct answer and a one-line explanation of why. Study them here, or take them as a timed test.

22 questionsBeginner 8 · Intermediate 7 · Advanced 7Answers + explanations
Take it as a timed test
Free PDF
All 389 questions & answers, in one file

DAX, Excel, Power BI, Fabric, certification practice and analyst interviews — every answer with the reason behind it. Print it, study it offline.

Instant download, plus the free Tuesday briefing. Unsubscribe in one click.

Beginner 8 questions

1Which function starts a Python formula in Excel?

  1. =RUNPY(
  2. =PANDAS(
  3. =PY(
  4. =PYTHON(
  5. =SCRIPT(
Show answerHide answer

C · =PY( Python in Excel formulas begin with the PY() function; the code runs and returns a value to the grid.

2Where does Python in Excel actually run?

  1. Locally on your PC
  2. In the web browser
  3. Fully offline
  4. On a local Anaconda install
  5. In the Microsoft Cloud (secure Azure container)
Show answerHide answer

E · In the Microsoft Cloud (secure Azure container) The code executes on Microsoft's cloud with a curated Anaconda distribution, not on your machine.

3The core Python library for tabular (row/column) data is…

  1. flask
  2. requests
  3. pandas
  4. pytest
  5. numpy
Show answerHide answer

C · pandas pandas provides the DataFrame — the row-and-column table used for data analysis.

4A pandas DataFrame is best described as…

  1. A single value
  2. A text string
  3. A chart object
  4. A 2-D labelled table of rows and columns
  5. A database connection
Show answerHide answer

D · A 2-D labelled table of rows and columns A DataFrame is a 2-D structure with labelled rows (index) and columns — like a worksheet range.

5To load a CSV file into a DataFrame you call…

  1. pd.load('file.csv')
  2. pd.read_csv('file.csv')
  3. pd.open_csv()
  4. open('file.csv')
  5. csv.to_frame()
Show answerHide answer

B · pd.read_csv('file.csv') pd.read_csv() parses a CSV into a DataFrame.

6In Python, indexing of a list starts at…

  1. It has no index
  2. Any value you set
  3. 0
  4. 1
  5. -1
Show answerHide answer

C · 0 Python sequences are zero-based: the first element is at index 0.

7df.head() returns…

  1. A single value
  2. The row count
  3. The first rows (5 by default)
  4. The column names only
  5. The last row
Show answerHide answer

C · The first rows (5 by default) head(n) shows the first n rows, defaulting to 5 — handy for a quick look.

8A comment in Python begins with…

  1. --
  2. #
  3. '
  4. //
  5. /* */
Show answerHide answer

B · # Everything after # on a line is a comment in Python.

Intermediate 7 questions

9df.groupby('Region')['Sales'].sum() does what?

  1. Totals Sales for each Region
  2. Removes duplicates
  3. Renames Sales
  4. Filters to one Region
  5. Sorts by Region
Show answerHide answer

A · Totals Sales for each Region groupby splits rows by the key, then sum aggregates Sales per group — like a PivotTable total.

10How do you keep only rows where Sales > 100?

  1. df.where(Sales)
  2. df.loc[100]
  3. df[df['Sales'] > 100]
  4. df.query(100)
  5. df.filter(100)
Show answerHide answer

C · df[df['Sales'] > 100] A boolean mask df[df['Sales'] > 100] returns the rows that satisfy the condition.

11df.merge(other, on='ID') is most like which Excel/SQL operation?

  1. A VLOOKUP / join on ID
  2. Concatenate text
  3. A PivotTable
  4. Conditional formatting
  5. Transpose
Show answerHide answer

A · A VLOOKUP / join on ID merge joins two DataFrames on a key column — the pandas equivalent of a lookup/join.

12The difference between .loc and .iloc is…

  1. loc returns a copy, iloc a view
  2. loc is faster always
  3. loc is label-based, iloc is integer-position-based
  4. iloc only works on columns
  5. No difference
Show answerHide answer

C · loc is label-based, iloc is integer-position-based .loc selects by row/column labels; .iloc selects by integer position.

13pandas' pivot_table() is the direct equivalent of…

  1. A macro
  2. A named range
  3. An Excel PivotTable
  4. A slicer
  5. A chart
Show answerHide answer

C · An Excel PivotTable pivot_table aggregates values across rows/columns just like an Excel PivotTable.

14df.dropna() does what?

  1. Drops all columns
  2. Sorts the data
  3. Drops rows containing missing (NaN) values
  4. Drops duplicate rows
  5. Fills missing values with 0
Show answerHide answer

C · Drops rows containing missing (NaN) values dropna removes rows (or columns) that contain NaN; fillna would replace them instead.

15A pandas Series is…

  1. A 1-D labelled array (one column)
  2. A SQL query
  3. A folder of files
  4. A 2-D table
  5. A chart
Show answerHide answer

A · A 1-D labelled array (one column) A Series is one labelled column; a DataFrame is a collection of Series sharing an index.

Advanced 7 questions

16Why prefer vectorized pandas/numpy operations over a Python for-loop?

  1. They run in optimized C, avoiding per-element Python overhead
  2. They avoid imports
  3. Loops are not allowed
  4. They look shorter only
  5. They use less disk
Show answerHide answer

A · They run in optimized C, avoiding per-element Python overhead Vectorized ops push the work into compiled C code, so they are far faster than element-by-element Python loops.

17df[df.a > 0]['b'] = 1 often triggers SettingWithCopyWarning because…

  1. Chained indexing is forbidden
  2. It may assign to a temporary copy, not the original frame
  3. 1 is not a valid value
  4. a must be a string
  5. b does not exist
Show answerHide answer

B · It may assign to a temporary copy, not the original frame Chained indexing can return a copy; use df.loc[df.a > 0, 'b'] = 1 to assign in place.

18df.apply(f, axis=1) applies f to…

  1. Nothing
  2. Each column
  3. Each row
  4. Only the first row
  5. The index only
Show answerHide answer

C · Each row axis=1 passes each row to the function; axis=0 (default) works down each column.

19pd.concat vs df.merge — the key difference is…

  1. merge only appends rows
  2. concat stacks along an axis; merge joins on key columns
  3. merge stacks vertically
  4. They are identical
  5. concat needs a key
Show answerHide answer

B · concat stacks along an axis; merge joins on key columns concat glues frames along rows or columns; merge performs a key-based join.

20Converting a repeated-text column with astype('category') mainly helps…

  1. Nothing
  2. Date parsing
  3. Accuracy
  4. Memory use and speed for repeated values
  5. Sorting order
Show answerHide answer

D · Memory use and speed for repeated values Category dtype stores each distinct value once, cutting memory and speeding group/compare operations.

21Multiple aggregations per group are done with…

  1. df.groupby('k').agg({'x':'sum','y':'mean'})
  2. df.merge('k')
  3. df.pivot()
  4. df.apply(all)
  5. df.sum().mean()
Show answerHide answer

A · df.groupby('k').agg({'x':'sum','y':'mean'}) agg with a dict applies a different aggregation to each column within each group.

22In Python in Excel, cells across the sheet are evaluated in…

  1. Column-major, bottom-up
  2. Only the selected cell
  3. Random order
  4. Reverse order
  5. Row-major order: top-to-bottom, left-to-right
Show answerHide answer

E · Row-major order: top-to-bottom, left-to-right Python in Excel runs in row-major order, so a later PY() cell can reference results from earlier rows.

What changed lately? Latest Python news, releases & questions →

Coming soon $19 one-time · early-access price
Prep Pro: full mock exams
  • Full-length, timed mock exams in the real PL-300, DP-600 and MO-201 format
  • Score breakdown by skill, with a study plan for your weak spots
  • New questions every month, written against the current exam outline

No payment now. We'll email you once, when it opens.

More technical interview questions