PrepPilotPractise free

Python for Data (pandas, NumPy) interview questions

DataFrames, vectorization, joins, groupby, plotting

17 questions · pandas · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What is a NumPy array and why is it preferred over Python lists for numerical computations?

A NumPy array is a fixed-type, multidimensional array that supports fast, vectorized operations. It's preferred over Python lists because it's much faster and uses less memory, especially for large numerical datasets.

How do you select a column from a pandas DataFrame?

You can select a column using either df['column_name'] or df.column_name. Both return a Series, but bracket notation is more robust, especially if the column name has spaces.

What does the .loc accessor do in pandas?

.loc is used for label-based indexing, allowing you to select rows and columns by their names rather than their integer positions.

How can you check for missing values in a DataFrame?

You can use df.isnull() to get a boolean mask of missing values, or df.isnull().sum() to count them per column.

Intermediate questions

Explain the difference between .loc and .iloc in pandas.

.loc accesses rows and columns by their labels, while .iloc uses integer positions. For example, .loc['row1', 'colA'] vs .iloc[0, 1]. Using the wrong accessor can lead to errors or unexpected results.

How would you aggregate sales data by region using pandas?

I'd use df.groupby('region')['sales'].sum() to group the data by region and sum the sales for each group. This provides a quick summary of sales performance across regions.

What are common pitfalls when merging DataFrames in pandas?

Common pitfalls include mismatched join keys, duplicate column names, and unintended Cartesian products if keys aren't unique. It's important to check key uniqueness and column overlaps before merging.

How do you handle missing values before training a machine learning model?

I inspect missing value patterns, then either fill them with statistical values like mean or median, or drop rows/columns with too many missing values, depending on the context and impact on the data.

Why is using .apply with custom functions discouraged for large DataFrames?

.apply is slow because it operates row-by-row in Python, whereas vectorized operations run in compiled code and are much faster. For large DataFrames, vectorization is crucial for performance.

How can you improve the memory usage of a pandas DataFrame?

Optimizing dtypes, such as converting object columns to category or using smaller integer types, can significantly reduce memory usage. Also, dropping unnecessary columns helps.

What is a pivot table in pandas and when would you use it?

A pivot table summarizes data by grouping and aggregating values across categories, similar to Excel. It's useful for reshaping data and quickly comparing metrics across multiple dimensions.

How can you use vectorization to speed up a calculation in NumPy?

By expressing the calculation as an array operation, such as result = a * b instead of looping through elements, NumPy leverages optimized C code for much faster execution.

What advantages does Polars offer over pandas for large datasets?

See the answer in the app, free

Senior questions

Describe how you would debug a failed merge operation that resulted in more rows than expected.

See the answer in the app, free

How would you handle a DataFrame with millions of rows and slow processing times?

See the answer in the app, free

What steps do you take to ensure notebook reproducibility and clarity when sharing with colleagues?

See the answer in the app, free

How would you visualize the distribution of a numerical column and interpret the results?

See the answer in the app, free

More Machine Learning & AI topics