Prev Next

Python / Data Science Essentials Interview Questions

1. What is NumPy and why is it significantly faster than plain Python lists for numerical work? 2. What are the main ways to create NumPy arrays? 3. How do NumPy array shape, reshape, and axis work? 4. What is NumPy broadcasting and how does it work? 5. How does NumPy boolean masking and fancy indexing work? 6. What are the most commonly used NumPy mathematical functions in data science? 7. What is a Pandas DataFrame and how does it differ from a NumPy array? 8. How do you read CSV, Excel, and JSON files into a Pandas DataFrame? 9. What is the difference between df.loc[] and df.iloc[] in Pandas? 10. How do you detect, handle, and fill missing values in a Pandas DataFrame? 11. What are the different ways to filter rows in a Pandas DataFrame? 12. How does Pandas groupby work and what aggregation patterns are most useful? 13. How do you merge and join DataFrames in Pandas, and what do the different join types mean? 14. When should you use df.apply() versus vectorised Pandas operations? 15. How do you use pd.pivot_table to summarise data? 16. How do you perform string operations on Pandas DataFrame columns? 17. How do you work with dates and times in Pandas? 18. What is Matplotlib and what are the key components of a figure? 19. What are the most common chart types in Matplotlib and when do you use each? 20. How do you create multi-panel figures with Matplotlib subplots? 21. What is Seaborn and how does it differ from Matplotlib? 22. What are the most important Seaborn plot types for exploratory data analysis? 23. How do you create and interpret a correlation heatmap with Seaborn? 24. What is Seaborn's FacetGrid and how does it enable multi-panel statistical plots? 25. How do you compute descriptive statistics on a Pandas DataFrame? 26. How do you reduce a Pandas DataFrame's memory usage through dtype optimisation? 27. How do you generate reproducible random data with NumPy? 28. How do you use value_counts() and pd.crosstab() to understand categorical data? 29. How do you style Matplotlib figures and save them for reports? 30. What is np.where and how is it used for conditional array creation? 31. What is Pandas method chaining and how does df.pipe() support it? 32. What does a typical exploratory data analysis (EDA) workflow look like in Python? 33. How do you stack, concatenate, and split NumPy arrays? 34. How do you detect and remove duplicate rows in a Pandas DataFrame? 35. How do you control colours and colour palettes in Matplotlib and Seaborn? 36. How do rolling and expanding window functions work in Pandas? 37. How do Seaborn jointplot and pairplot help explore multivariate relationships? 38. What are the key performance tips when using NumPy for large-scale data processing? 39. How do you visualise regression results and residuals using Seaborn and Matplotlib? 40. How do you process large CSV files that don't fit in memory using Pandas? 41. How do you add annotations and text to Matplotlib charts? 42. How do you quickly extract top/bottom rows and random samples from a Pandas DataFrame? 43. How is NumPy linear algebra used in data science applications? 44. How do you compare distributions across categories using Seaborn categorical plots? 45. How do you build an end-to-end data cleaning and visualisation pipeline with NumPy, Pandas, and Seaborn?

1. What is NumPy and why is it significantly faster than plain Python lists for numerical work?

NumPy (Numerical Python) is the foundational library for scientific computing in Python. At its core it provides the ndarray — an N-dimensional array of a single, fixed data type stored in a contiguous block of memory. That single design decision is the source of almost all of NumPy's performanc...

Read full answer

2. What are the main ways to create NumPy arrays?

Knowing the idiomatic array-creation functions is a baseline NumPy skill. Each function is designed for a specific situation and picking the right one keeps code readable and avoids unnecessary copies. import numpy as np # From Python sequences a = np . array([ 1 , 2 , 3 , 4 ]) # 1-D, dtype infer...

Read full answer

3. How do NumPy array shape, reshape, and axis work?

Every NumPy array has a shape attribute — a tuple giving the size along each dimension. Shape is fundamental because most NumPy operations depend on it, and shape mismatches are the most common source of errors in numerical code. import numpy as np a = np . arange( 24 ) print(a . shape) # (24,) #...

Read full answer

4. What is NumPy broadcasting and how does it work?

Broadcasting is the set of rules NumPy uses to perform element-wise operations on arrays of different but compatible shapes, without physically copying data to make them the same size. It is one of the most powerful and often misunderstood NumPy features. The rules, applied dimension by dimension...

Read full answer

5. How does NumPy boolean masking and fancy indexing work?

Beyond basic integer indexing, NumPy supports two advanced selection mechanisms that are essential for data-cleaning and filtering tasks. Boolean masking : A comparison on an array produces a boolean array of the same shape. Passing that boolean array back as an index selects only the True positi...

Read full answer

6. What are the most commonly used NumPy mathematical functions in data science?

NumPy ships a comprehensive set of universal functions (ufuncs) — compiled, vectorised operations that apply element-wise across the full array without Python loops. Knowing these avoids writing slow manual loops for standard computations. import numpy as np a = np . array([ 1.0 , 4.0 , 9.0 , 16....

Read full answer

7. What is a Pandas DataFrame and how does it differ from a NumPy array?

A Pandas DataFrame is a two-dimensional, labelled data structure — think of it as a spreadsheet or a SQL table in memory. Rows and columns both have labels (the index and the column names ), and each column can hold a different data type. A Series is the single-column equivalent. DataFrame vs Num...

Read full answer

8. How do you read CSV, Excel, and JSON files into a Pandas DataFrame?

Pandas has a family of pd.read_* functions that handle virtually every common data format. Getting data in is usually the first step of any data science workflow, so these functions deserve close attention. import pandas as pd # --- CSV --- df = pd . read_csv( 'sales.csv' ) # Common options: df =...

Read full answer

9. What is the difference between df.loc[] and df.iloc[] in Pandas?

This distinction is tested in almost every Pandas interview. The short version: loc selects by label ; iloc selects by integer position . They look similar but behave very differently, especially when the DataFrame index is not a default RangeIndex. import pandas as pd df = pd . DataFrame({ 'name...

Read full answer

10. How do you detect, handle, and fill missing values in a Pandas DataFrame?

Missing values are represented in Pandas as NaN (float Not-a-Number from NumPy), NaT (Not-a-Time for datetime columns), or pd.NA (the newer nullable integer/string missing marker). Handling them correctly is the most time-consuming step of real-world data cleaning. import pandas as pd import nump...

Read full answer

11. What are the different ways to filter rows in a Pandas DataFrame?

Row filtering is one of the most frequent DataFrame operations. Pandas provides several syntaxes, each with different readability and performance trade-offs. import pandas as pd df = pd . DataFrame({ 'city' : [ 'NYC' , 'LA' , 'NYC' , 'Chicago' , 'LA' ], 'revenue' : [ 120 , 85 , 200 , 55 , 140 ], ...

Read full answer

12. How does Pandas groupby work and what aggregation patterns are most useful?

GroupBy is the Pandas implementation of the split-apply-combine pattern: split the DataFrame into groups by one or more column values, apply an aggregation or transformation to each group, and combine the results into a new DataFrame. It is the primary tool for summary statistics on tabular data....

Read full answer

13. How do you merge and join DataFrames in Pandas, and what do the different join types mean?

Real-world data lives in multiple tables. Pandas merge() implements SQL-style joins, and concat() stacks DataFrames. Choosing the right join type prevents silently losing or duplicating rows. Pandas Join Types how= Keeps rows from Missing matches become 'inner' Both DataFrames (intersection) NaN ...

Read full answer

14. When should you use df.apply() versus vectorised Pandas operations?

apply() runs a Python function on every row or column of a DataFrame. It is the most flexible transformation tool in Pandas but also the slowest because it falls back to a Python-level loop under the hood. import pandas as pd import numpy as np df = pd . DataFrame({ 'price' : [ 10.5 , 20.0 , 8.75...

Read full answer

15. How do you use pd.pivot_table to summarise data?

pd.pivot_table reshapes and aggregates a DataFrame simultaneously, producing a cross-tabulation — exactly like a spreadsheet pivot table. It is the go-to function for producing summary reports broken down by two categorical dimensions. import pandas as pd sales = pd . DataFrame({ 'region' : [ 'Ea...

Read full answer

16. How do you perform string operations on Pandas DataFrame columns?

Pandas exposes string methods through the .str accessor on object-dtype Series. These operations are vectorised over the whole column — no explicit loop needed — and handle NaN values gracefully (they propagate as NaN rather than raising an error). import pandas as pd df = pd . DataFrame({ 'name'...

Read full answer

17. How do you work with dates and times in Pandas?

Time-series data is everywhere in data science — sales by day, sensor readings by second, user activity by hour. Pandas has first-class datetime support built on NumPy's datetime64 type and Python's datetime module. import pandas as pd df = pd . DataFrame({ 'date_str' : [ '2024-01-15' , '2024-02-...

Read full answer

18. What is Matplotlib and what are the key components of a figure?

Matplotlib is Python's foundational plotting library, originally modelled after MATLAB's plotting API. Almost every other Python visualisation library (Seaborn, Pandas .plot(), Plotly static exports) either wraps Matplotlib or uses it as a rendering backend. Understanding the object hierarchy is ...

Read full answer

19. What are the most common chart types in Matplotlib and when do you use each?

Choosing the right chart type communicates data clearly; choosing the wrong one obscures it. Here are the workhorses of exploratory data analysis: import matplotlib.pyplot as plt import numpy as np fig, axes = plt . subplots( 2 , 3 , figsize = ( 14 , 8 )) # 1. Line chart — trends over time or o...

Read full answer

20. How do you create multi-panel figures with Matplotlib subplots?

Multi-panel figures are standard in data science reports — comparing multiple variables or time periods side by side. Matplotlib provides several ways to arrange subplots. import matplotlib.pyplot as plt import numpy as np x = np . linspace( 0 , 10 , 200 ) # --- Regular grid --- fig, axes = plt ....

Read full answer

21. What is Seaborn and how does it differ from Matplotlib?

Seaborn is a high-level statistical visualisation library built on top of Matplotlib. Where Matplotlib gives you full control over every pixel, Seaborn provides opinionated, attractive defaults and plot types designed specifically for statistical exploration — with far less boilerplate code. Matp...

Read full answer

22. What are the most important Seaborn plot types for exploratory data analysis?

Seaborn divides its plots into relational (relationship between variables), distributional (distribution of a single variable), and categorical (comparison across categories). Knowing when to use each makes EDA far more efficient. import seaborn as sns import matplotlib.pyplot as plt tips = sns ....

Read full answer

23. How do you create and interpret a correlation heatmap with Seaborn?

A correlation heatmap is one of the first plots every data scientist makes on a new dataset. It shows the Pearson (or other) correlation coefficient between every pair of numeric features as a colour-coded grid, immediately revealing which variables move together and which do not. import pandas a...

Read full answer

24. What is Seaborn's FacetGrid and how does it enable multi-panel statistical plots?

FacetGrid is Seaborn's mechanism for trellis/small-multiples plots — the same chart repeated across different subsets of the data, defined by one or more categorical columns. It is one of Seaborn's most powerful features for exploring interaction effects between variables. import seaborn as sns i...

Read full answer

25. How do you compute descriptive statistics on a Pandas DataFrame?

Descriptive statistics summarise the central tendency, spread, and shape of a dataset. Pandas df.describe() is the starting point for any exploratory analysis, but knowing the individual methods gives you more precise control. import pandas as pd import numpy as np df = pd . read_csv( 'housing.cs...

Read full answer

26. How do you reduce a Pandas DataFrame's memory usage through dtype optimisation?

DataFrames loaded from CSV often use unnecessarily large dtypes — 64-bit integers for values that fit in 8 bits, generic object dtype for repeated string categories. Downcasting dtypes can reduce memory by 4–8× without any data loss, enabling analysis of larger datasets within available RAM. impo...

Read full answer

27. How do you generate reproducible random data with NumPy?

Reproducibility is a core requirement of data science — experiments, train/test splits, and simulations must produce the same result every run so that results can be verified and shared. NumPy's random number generation is the building block for all of this. import numpy as np # --- Legacy API (s...

Read full answer

28. How do you use value_counts() and pd.crosstab() to understand categorical data?

Categorical columns are understood by counting their frequencies and cross-tabulating them against other variables. These two tools answer the questions 'what values exist and how often?' and 'how are two categorical variables related?' import pandas as pd tips = pd . read_csv( 'https://raw.githu...

Read full answer

29. How do you style Matplotlib figures and save them for reports?

The default Matplotlib style is functional but plain. For presentations and reports you need publication-quality output — chosen colour palettes, correct font sizes, no chart junk, and lossless or high-resolution raster output. import matplotlib.pyplot as plt import numpy as np # --- Using a styl...

Read full answer

30. What is np.where and how is it used for conditional array creation?

np.where is NumPy's vectorised if/else for arrays. In its three-argument form it returns a new array built element-by-element: where the condition is True, use values from x ; where False, use values from y . It is the correct alternative to writing a Python loop with an if-statement inside. impo...

Read full answer

31. What is Pandas method chaining and how does df.pipe() support it?

Method chaining is the style of writing data transformations as a single expression where each step's result is the input to the next. It avoids creating intermediate variables, reads like a pipeline, and makes the data flow explicit from top to bottom. import pandas as pd # --- Without chaining ...

Read full answer

32. What does a typical exploratory data analysis (EDA) workflow look like in Python?

EDA is the first thing you do with a new dataset before any modelling. The goal is to understand the data's structure, quality, and relationships, and to spot problems (wrong dtypes, missing values, outliers, data leakage) before they propagate into a model. import pandas as pd import numpy as np...

Read full answer

33. How do you stack, concatenate, and split NumPy arrays?

Combining and splitting arrays is a frequent operation in data preprocessing — assembling feature matrices from multiple sources, or splitting a dataset into folds for cross-validation. import numpy as np a = np . array([[ 1 , 2 ], [ 3 , 4 ]]) b = np . array([[ 5 , 6 ], [ 7 , 8 ]]) # --- Concaten...

Read full answer

34. How do you detect and remove duplicate rows in a Pandas DataFrame?

Duplicate rows silently inflate counts, distort means, and can cause data leakage between training and test sets. Pandas provides duplicated() and drop_duplicates() for systematic duplicate management. import pandas as pd df = pd . DataFrame({ 'order_id' : [ 1 , 2 , 2 , 3 , 4 , 4 ], 'product' : [...

Read full answer

35. How do you control colours and colour palettes in Matplotlib and Seaborn?

Colour is one of the most impactful design decisions in a chart. Used correctly it encodes information; used poorly it confuses or misleads. Both Matplotlib and Seaborn give you fine-grained control. import matplotlib.pyplot as plt import seaborn as sns import numpy as np # --- Matplotlib colour ...

Read full answer

36. How do rolling and expanding window functions work in Pandas?

Window functions compute statistics over a sliding or expanding subset of rows, essential for time-series smoothing, trend detection, and feature engineering. Unlike groupby aggregations, window functions return a result for every row, preserving the original index. import pandas as pd import num...

Read full answer

37. How do Seaborn jointplot and pairplot help explore multivariate relationships?

When you have more than one numeric variable, the next step after individual histograms is to understand relationships between pairs. Seaborn's jointplot and pairplot automate this exploration with minimal code. import seaborn as sns import matplotlib.pyplot as plt penguins = sns . load_dataset( ...

Read full answer

38. What are the key performance tips when using NumPy for large-scale data processing?

NumPy is fast by default, but a few common mistakes can undermine that speed. Knowing these patterns makes the difference between code that runs in seconds and code that runs in minutes. import numpy as np n = 10_000_000 arr = rng . random(n) # 1. AVOID Python loops — always prefer ufuncs # Slo...

Read full answer

39. How do you visualise regression results and residuals using Seaborn and Matplotlib?

After fitting any regression model, visualising the residuals (actual - predicted values) is mandatory. Patterns in residuals reveal model assumptions violations: non-linearity, heteroscedasticity, or non-normality of errors. import pandas as pd import numpy as np import seaborn as sns import mat...

Read full answer

40. How do you process large CSV files that don't fit in memory using Pandas?

When a CSV is larger than available RAM, loading it with a plain pd.read_csv causes a MemoryError . Pandas provides three strategies: chunking, selective loading, and dtype optimisation. import pandas as pd import numpy as np # --- Strategy 1: Read only necessary columns and rows --- df = pd . re...

Read full answer

41. How do you add annotations and text to Matplotlib charts?

Annotations turn a chart into a story — highlighting a key data point, marking a threshold, or labelling significant events on a timeline. Matplotlib provides ax.annotate() for arrow-and-text annotations and ax.text() for free-form text placement. import matplotlib.pyplot as plt import numpy as n...

Read full answer

42. How do you quickly extract top/bottom rows and random samples from a Pandas DataFrame?

During EDA you often need to inspect extremes (the highest-revenue customers, the worst-performing products) or draw a random sample for quick analysis. Pandas provides concise methods for each of these. import pandas as pd import numpy as np rng = np . random . default_rng( 42 ) df = pd . DataFr...

Read full answer

43. How is NumPy linear algebra used in data science applications?

Linear algebra underpins almost all of machine learning — from computing gradients to PCA to solving systems of equations. NumPy's linalg submodule provides production-grade implementations of the core operations. import numpy as np # --- Solving a system of linear equations: Ax = b --- # 2x + y ...

Read full answer

44. How do you compare distributions across categories using Seaborn categorical plots?

Comparing how a numeric variable's distribution differs across groups is one of the most common analytical tasks. Seaborn's categorical plot family gives you progressively more information from left to right: bar (mean only) → box (five-number summary) → violin (full distribution shape) → strip/s...

Read full answer

45. How do you build an end-to-end data cleaning and visualisation pipeline with NumPy, Pandas, and Seaborn?

Combining all three libraries in a coherent pipeline is what data science interviews and take-home assignments test. Below is a realistic miniature pipeline that demonstrates the key integration points. import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt s...

Read full answer

«
»

Comments & Discussions