All interview guides

Pandas Interview Questions and Answers

24 questions that come up in Pandas technical interviews, each with the answer and an explanation of why it is right.

Test yourself — 90 question bank

1. What is Pandas?

Beginner

Answer: Python library for data manipulation and analysis

Pandas is a powerful Python library providing data structures and tools for data manipulation and analysis. Built on NumPy, it's essential for data science.

2. What is vectorization in Pandas?

Advanced

Answer: Using array operations instead of loops

Vectorization uses NumPy array operations instead of Python loops. Dramatically faster. Use built-in methods, broadcasting, avoid apply/iterrows when possible.

3. What is groupby()?

Intermediate

Answer: Groups data by column values for aggregation

groupby() splits data into groups based on criteria. Apply aggregation functions (mean, sum, count). Foundation of split-apply-combine pattern in Pandas.

4. What are the two main data structures in Pandas?

Beginner

Answer: Series and DataFrame

Series (1D labeled array) and DataFrame (2D labeled data structure) are the two primary Pandas data structures. DataFrame is most commonly used.

5. What is the most efficient way to iterate?

Advanced

Answer: Avoid iteration; use vectorization

Best: avoid iteration with vectorization. If needed: itertuples() > iterrows() > loop. itertuples() fastest. iterrows() slow due to Series creation. Never use loop.

6. How do you perform aggregation on groups?

Intermediate

Answer: df.groupby('col').agg(function)

Use df.groupby('col').agg(func). Can use built-in (mean, sum) or custom functions. Pass multiple functions or dict for different columns.

7. What is merge()?

Intermediate

Answer: Joins DataFrames like SQL join

pd.merge(df1, df2) performs database-style joins. Types: inner, outer, left, right. Join on columns or indices. Similar to SQL JOIN operations.

8. What is a Series?

Beginner

Answer: One-dimensional labeled array

Series is a one-dimensional labeled array that can hold any data type. Like a column in a spreadsheet or dictionary with index labels.

9. What is category dtype?

Advanced

Answer: Memory-efficient storage for categorical data

Category dtype stores categorical data efficiently. Reduces memory for repeated strings. Ordered/unordered. Much faster operations. Convert with astype('category').

10. What is the difference between merge and join?

Intermediate

Answer: merge joins on columns, join on indices

merge joins on columns (more flexible), join primarily on indices. Both achieve similar results. merge is more explicit and commonly used.

11. What is a DataFrame?

Beginner

Answer: Two-dimensional labeled data structure with columns

DataFrame is a 2D labeled data structure with columns of potentially different types. Like a spreadsheet or SQL table. Most commonly used Pandas structure.

12. What is sparse data?

Advanced

Answer: Efficient storage for data with many missing values

Sparse data structures efficiently store data with many missing/zero values. Use pd.SparseDtype. Saves memory significantly for sparse datasets.

13. How do you import Pandas?

Beginner

Answer: All of the above

All methods work, but import pandas as pd is the standard convention. Provides shorter alias while being clear and avoiding namespace pollution.

14. What is chunking?

Advanced

Answer: Processing large files in chunks

Chunking processes large files in chunks: pd.read_csv(chunksize=10000). Iterate over chunks. Prevents memory errors. Essential for big data in Pandas.

15. What is concat()?

Intermediate

Answer: Concatenates DataFrames along axis

pd.concat([df1, df2]) concatenates along axis. axis=0 (default) stacks vertically, axis=1 horizontally. Use for combining DataFrames without keys.

16. How do you create a DataFrame from a dictionary?

Beginner

Answer: pd.DataFrame(dict)

Use pd.DataFrame(dictionary). Keys become column names, values become column data. Most common way to create DataFrame from Python data.

17. What is pivot()?

Intermediate

Answer: Reshapes data from long to wide format

pivot() reshapes data: unique values of column become new columns. Creates pivot table. Use pivot_table() for aggregation with duplicate entries.

18. What is pipe()?

Advanced

Answer: Chains operations for readable code

pipe() enables method chaining with functions. df.pipe(func1).pipe(func2). Creates readable data pipelines. Alternative to nested function calls.

19. What is pivot_table()?

Intermediate

Answer: Creates spreadsheet-style pivot table with aggregation

pivot_table() creates pivot table with aggregation. Handles duplicate entries. Specify values, index, columns, aggfunc. More flexible than pivot().

20. How do you read a CSV file?

Beginner

Answer: pd.read_csv('file.csv')

pd.read_csv('filename.csv') reads CSV file into DataFrame. Most common data import method. Supports many parameters for customization (sep, header, etc.).

21. What is numba with Pandas?

Advanced

Answer: JIT compilation for fast custom operations

Numba JIT-compiles Python code to machine code. Use @jit with apply: df.apply(numba_func, engine='numba'). Dramatic speedups for custom operations.

22. What is Dask?

Advanced

Answer: Parallel computing library for larger-than-memory datasets

Dask provides parallel computing for datasets larger than memory. Similar API to Pandas. Lazy evaluation, task graphs. Use when Pandas hits memory limits.

23. How do you display first 5 rows?

Beginner

Answer: df.head()

df.head() displays first 5 rows by default. df.head(n) shows first n rows. Quick way to preview data. Similar: df.tail() for last rows.

24. What is melt()?

Intermediate

Answer: Reshapes data from wide to long format

melt() unpivots DataFrame from wide to long format. Opposite of pivot. Specify id_vars (identifier columns) and value_vars (columns to unpivot).

Ready to test yourself?

The full Pandas bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.

Take the Pandas quiz