InterviewStack.io LogoInterviewStack.io

Python for Data Analysis Questions

Covers the practical use of Python and its data libraries to perform data ingestion, cleaning, transformation, analysis, and aggregation. Candidates should be able to manipulate data frames, perform complex grouping and aggregation operations, merge and join multiple data sources, and implement efficient vectorized operations using libraries such as Pandas and NumPy. Expect to write clear, idiomatic Python with appropriate error handling, input validation, and small tests or assertions. At more senior levels, discuss performance trade offs and scalability strategies such as choosing NumPy vectorization versus Pandas, and when to adopt alternative tools like Polars or Dask for very large datasets, as well as techniques for memory management, profiling, and incremental or streaming processing. Also cover reproducibility, serialization formats, and integrating analysis into pipelines.

MediumTechnical
62 practiced
A categorical column 'city' has 10k unique values across 10M rows. Describe the memory and performance benefits of converting this column to pandas.Categorical, show code to do it safely, and list pitfalls (e.g., high-cardinality categories, sorting, category reordering). When would you avoid using Categorical?
EasyTechnical
62 practiced
Given a DataFrame `df` with columns ['user_id', 'feature1'] where feature1 contains NaNs, write pandas code to replace NaNs with the median of feature1 for that user's group; if a user's group median is not available (all NaNs), use the global median. Ensure the dtype remains numeric. Provide a short explanation of your approach.
HardSystem Design
48 practiced
You need to join a 100M-row feature table with a 1M-row training example list to produce training data without blowing memory. Describe efficient strategies in Python: partitioned (sharded) joins by key, hash-based streaming join, bloom-filter pre-filtering, using on-disk keyed stores, or pushing joins into a database. For the partitioned approach provide a code sketch showing how to partition, join, and reduce memory usage.
MediumTechnical
47 practiced
For each user, resample their event counts to a daily frequency, fill missing days with zero, compute a 7-day trailing rolling mean (aligned to the right), and return a DataFrame with columns ['user_id', 'date', 'daily_count', 'rolling_7d_mean']. Provide memory- and performance-conscious pandas code that avoids Python loops and explain potential bottlenecks when there are millions of users.
MediumTechnical
50 practiced
You have duplicated transaction records and want to deduplicate with tolerance: two records with the same user_id, amount equal, and timestamps within 2 seconds should be considered duplicates. Describe and implement a pandas approach to identify and drop such duplicates while keeping the earliest record. Explain complexity and edge cases.

Unlock Full Question Bank

Get access to hundreds of Python for Data Analysis interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.