← 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
Beginner 8 questions
1Which function starts a Python formula in Excel?
- =RUNPY(
- =PANDAS(
- =PY(
- =PYTHON(
- =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?
- Locally on your PC
- In the web browser
- Fully offline
- On a local Anaconda install
- 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…
- flask
- requests
- pandas
- pytest
- 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…
- A single value
- A text string
- A chart object
- A 2-D labelled table of rows and columns
- 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…
- pd.load('file.csv')
- pd.read_csv('file.csv')
- pd.open_csv()
- open('file.csv')
- 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…
- It has no index
- Any value you set
- 0
- 1
- -1
Show answerHide answer
C · 0 Python sequences are zero-based: the first element is at index 0.
7df.head() returns…
- A single value
- The row count
- The first rows (5 by default)
- The column names only
- 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…
- --
- #
- '
- //
- /* */
Show answerHide answer
B · # Everything after # on a line is a comment in Python.
Intermediate 7 questions
9df.groupby('Region')['Sales'].sum() does what?
- Totals Sales for each Region
- Removes duplicates
- Renames Sales
- Filters to one Region
- 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?
- df.where(Sales)
- df.loc[100]
- df[df['Sales'] > 100]
- df.query(100)
- 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?
- A VLOOKUP / join on ID
- Concatenate text
- A PivotTable
- Conditional formatting
- 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…
- loc returns a copy, iloc a view
- loc is faster always
- loc is label-based, iloc is integer-position-based
- iloc only works on columns
- 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…
- A macro
- A named range
- An Excel PivotTable
- A slicer
- 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?
- Drops all columns
- Sorts the data
- Drops rows containing missing (NaN) values
- Drops duplicate rows
- 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…
- A 1-D labelled array (one column)
- A SQL query
- A folder of files
- A 2-D table
- 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?
- They run in optimized C, avoiding per-element Python overhead
- They avoid imports
- Loops are not allowed
- They look shorter only
- 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…
- Chained indexing is forbidden
- It may assign to a temporary copy, not the original frame
- 1 is not a valid value
- a must be a string
- 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…
- Nothing
- Each column
- Each row
- Only the first row
- 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…
- merge only appends rows
- concat stacks along an axis; merge joins on key columns
- merge stacks vertically
- They are identical
- 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…
- Nothing
- Date parsing
- Accuracy
- Memory use and speed for repeated values
- 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…
- df.groupby('k').agg({'x':'sum','y':'mean'})
- df.merge('k')
- df.pivot()
- df.apply(all)
- 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…
- Column-major, bottom-up
- Only the selected cell
- Random order
- Reverse order
- 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 →
More technical interview questions