← Blog
INTERVIEW PREP — INDIA 202640 Questions

Python Interview Questions for
Data Analysts — India 2026 (Top 40 Q&A)

Covers Pandas, NumPy, data cleaning, EDA, visualisation, and tricky logic questions — with difficulty levels and code examples. Curated for data analyst interviews at Indian IT services, product companies, and startups.

SQL Interview Questions →Power BI Interview Questions
BasicsData CleaningSelection & FilteringGroupBy & AggregationMerge & JoinPivot & ReshapeString OperationsApply & LambdaNumPyEDAVisualisationLogicPerformance
Beginner
Intermediate
Advanced

Basics

Beginner

Q: What is a DataFrame in Pandas?

A DataFrame is a two-dimensional, labelled data structure in Pandas — similar to a spreadsheet or SQL table. It has rows (indexed) and named columns. Each column can hold data of a different type. It is the primary structure used for data analysis in Python.

Beginner

Q: What is the difference between a Series and a DataFrame in Pandas?

A Series is one-dimensional — a single column of data with an index. A DataFrame is two-dimensional — multiple Series sharing the same index. A DataFrame can be thought of as a dictionary of Series objects.

Beginner

Q: How do you read a CSV file into a Pandas DataFrame?

Use pd.read_csv("filename.csv"). Key optional parameters: sep to specify delimiter, header to specify which row is the header, index_col to set a column as the index, and dtype to specify column data types explicitly.

import pandas as pd
df = pd.read_csv("data.csv")
df = pd.read_csv("data.csv", sep="|", index_col=0)
Beginner

Q: How do you check the shape, column names, and data types of a DataFrame?

Use df.shape for (rows, columns), df.columns for column names, df.dtypes for data types per column, and df.info() for a combined summary. df.head() and df.tail() show the first and last 5 rows.

print(df.shape)   # (1000, 12)
print(df.columns) # Index(['id', 'name', ...])
print(df.dtypes)
df.info()

Data Cleaning

Beginner

Q: How do you find and count missing values in a DataFrame?

Use df.isnull().sum() to count nulls per column. df.isnull().sum().sum() gives the total count across the entire DataFrame. df[df["column"].isnull()] filters rows where a specific column is null.

df.isnull().sum()           # nulls per column
df.isnull().sum().sum()     # total nulls
df[df["salary"].isnull()]   # rows with null salary
Beginner

Q: How do you handle missing values in Pandas?

Three main approaches: (1) Drop — df.dropna() removes rows with any null; df.dropna(subset=["col"]) drops only when specific column is null. (2) Fill — df.fillna(0) fills with a constant; df["col"].fillna(df["col"].mean()) fills with mean. (3) Forward/back fill — df.fillna(method="ffill") propagates previous value.

Intermediate

Q: How do you remove duplicate rows in a DataFrame?

Use df.drop_duplicates() to remove exact duplicate rows. df.drop_duplicates(subset=["email"]) removes duplicates based on a specific column. keep="first" (default) keeps the first occurrence; keep="last" keeps the last; keep=False drops all duplicates.

df = df.drop_duplicates()
df = df.drop_duplicates(subset=["customer_id"], keep="first")
Intermediate

Q: How do you convert a column to a different data type in Pandas?

Use df["col"].astype(). Common conversions: astype(int), astype(float), astype(str). For dates: pd.to_datetime(df["date_col"]). For numeric parsing with errors: pd.to_numeric(df["col"], errors="coerce") converts non-numeric to NaN.

df["age"] = df["age"].astype(int)
df["date"] = pd.to_datetime(df["date"])
df["salary"] = pd.to_numeric(df["salary"], errors="coerce")

Selection & Filtering

Beginner

Q: What is the difference between .loc and .iloc in Pandas?

.loc is label-based — you select by row/column names. .iloc is integer position-based — you select by row/column number (0-indexed). df.loc[0, "name"] selects row with index label 0 and column "name". df.iloc[0, 1] selects the first row and second column by position.

Beginner

Q: How do you filter rows based on a condition in Pandas?

Use boolean indexing: df[df["salary"] > 50000] returns rows where salary exceeds 50,000. Multiple conditions use & (and) or | (or) with parentheses: df[(df["city"] == "Delhi") & (df["salary"] > 50000)].

high_earners = df[df["salary"] > 50000]
delhi_high = df[(df["city"] == "Delhi") & (df["salary"] > 50000)]
Intermediate

Q: How do you select rows where a column value is in a list?

Use the .isin() method: df[df["city"].isin(["Delhi", "Mumbai", "Noida"])]. To select rows NOT in the list, negate it: df[~df["city"].isin(["Delhi", "Mumbai"])].

top_cities = ["Delhi", "Mumbai", "Bengaluru"]
df_top = df[df["city"].isin(top_cities)]

GroupBy & Aggregation

Intermediate

Q: How does groupby work in Pandas?

df.groupby("column") splits the DataFrame by unique values of the column. Chain an aggregation function: .sum(), .mean(), .count(), .max(), .min(). df.groupby("department")["salary"].mean() gives average salary per department.

df.groupby("department")["salary"].mean()
df.groupby(["city", "dept"])["revenue"].sum()
Intermediate

Q: How do you apply multiple aggregations with groupby?

Use .agg() with a dictionary: df.groupby("department").agg({"salary": ["mean", "max", "count"], "age": "median"}). This returns a multi-level column DataFrame with each aggregation as a separate column.

result = df.groupby("department").agg(
    avg_salary=("salary", "mean"),
    max_salary=("salary", "max"),
    headcount=("id", "count")
).reset_index()
Intermediate

Q: What does reset_index() do after a groupby?

After groupby().agg(), the grouped column becomes the index. reset_index() converts it back to a regular column, making the result easier to work with (filter, merge, export). It is almost always used after groupby operations in data analysis.

Merge & Join

Intermediate

Q: How do you merge two DataFrames in Pandas?

Use pd.merge(df1, df2, on="key", how="inner"). The how parameter controls join type: "inner" (matching rows only), "left" (all df1 rows), "right" (all df2 rows), "outer" (all rows from both). Equivalent to SQL JOINs.

merged = pd.merge(orders, customers, on="customer_id", how="left")
merged = pd.merge(df1, df2, left_on="emp_id", right_on="id", how="inner")
Intermediate

Q: What is the difference between merge and concat in Pandas?

merge() joins DataFrames horizontally based on a common key — like a SQL JOIN. concat() stacks DataFrames vertically (axis=0, more rows) or horizontally (axis=1, more columns) by position — like SQL UNION ALL. Use merge for relational joins, concat for appending rows or aligning column-by-column.

Pivot & Reshape

Intermediate

Q: How do you create a pivot table in Pandas?

Use df.pivot_table(values="sales", index="month", columns="region", aggfunc="sum"). This is the Pandas equivalent of Excel pivot tables. The index becomes rows, columns become column headers, values is the metric, and aggfunc is the aggregation (sum, mean, count).

pivot = df.pivot_table(
    values="sales",
    index="month",
    columns="region",
    aggfunc="sum",
    fill_value=0
)
Intermediate

Q: What do melt and pivot_table do, and when do you use each?

pivot_table reshapes long data to wide (rows to columns) — good for summary tables. melt() does the reverse — wide to long — unpivoting columns back into rows. melt is useful when you have separate columns for each month or category and need to normalise the structure for analysis or charting.

String Operations

Intermediate

Q: How do you work with string columns in Pandas?

Use the .str accessor on a string column. Common operations: df["name"].str.upper(), df["name"].str.strip(), df["email"].str.contains("@gmail"), df["city"].str.replace("Bombay", "Mumbai"). These are vectorised — they apply to the entire column at once, much faster than a loop.

df["name"] = df["name"].str.strip().str.title()
df_gmail = df[df["email"].str.contains("@gmail.com", na=False)]

Apply & Lambda

Intermediate

Q: What does apply() do in Pandas?

apply() lets you apply a custom function to each row or column. df["col"].apply(func) applies to each element of a Series. df.apply(func, axis=1) applies a function to each row. Use apply() when built-in vectorised operations do not cover your logic — but prefer vectorised operations for performance.

df["grade"] = df["score"].apply(lambda x: "A" if x >= 90 else ("B" if x >= 75 else "C"))
df["full_name"] = df.apply(lambda row: row["first"] + " " + row["last"], axis=1)

NumPy

Beginner

Q: What is NumPy and why is it used in data analytics?

NumPy (Numerical Python) is the foundation for numerical computing in Python. It provides the ndarray (n-dimensional array) which Pandas DataFrames are built on. NumPy operations are significantly faster than Python loops because they are implemented in C. In analytics, it is used for mathematical operations, array slicing, broadcasting, and as the backbone for Pandas and Scikit-learn.

Intermediate

Q: What is broadcasting in NumPy?

Broadcasting allows NumPy to perform operations on arrays of different shapes without explicit looping. When you add a scalar to an array, NumPy "broadcasts" the scalar to match the array shape. Similarly, a (3,1) array added to a (1,4) array broadcasts to produce a (3,4) result. This makes vectorised operations concise and fast.

EDA

Intermediate

Q: What are the key steps in an Exploratory Data Analysis (EDA) workflow?

Standard EDA workflow: (1) Load and inspect data — df.shape, df.info(), df.describe(); (2) Check missing values — df.isnull().sum(); (3) Check duplicates; (4) Understand distributions — histograms, boxplots; (5) Check correlations — df.corr(), heatmap; (6) Identify outliers — IQR method or boxplots; (7) Analyse relationships between variables — scatter plots, groupby summaries.

Intermediate

Q: How do you detect outliers in a numeric column using Python?

IQR (Interquartile Range) method: Q1 = df["col"].quantile(0.25), Q3 = df["col"].quantile(0.75), IQR = Q3 - Q1. Outliers are values below Q1 - 1.5*IQR or above Q3 + 1.5*IQR. Visualise with df["col"].plot(kind="box"). For normally distributed data, Z-score method is also used.

Q1 = df["salary"].quantile(0.25)
Q3 = df["salary"].quantile(0.75)
IQR = Q3 - Q1
outliers = df[(df["salary"] < Q1 - 1.5*IQR) | (df["salary"] > Q3 + 1.5*IQR)]

Visualisation

Beginner

Q: How do you create a bar chart and line chart in Python?

Using Matplotlib: plt.bar(x, y) for bar chart, plt.plot(x, y) for line chart. Using Pandas directly: df["col"].plot(kind="bar"), df["col"].plot(kind="line"). Seaborn offers more polished charts: sns.barplot(data=df, x="city", y="sales"), sns.lineplot(data=df, x="month", y="revenue").

import matplotlib.pyplot as plt
plt.bar(df["city"], df["sales"])
plt.title("Sales by City")
plt.show()
Intermediate

Q: What is the difference between Matplotlib and Seaborn?

Matplotlib is the base library — lower-level, more control, more code. Seaborn is built on Matplotlib — higher-level, better default aesthetics, simpler syntax for statistical charts (heatmaps, pairplots, violin plots). For quick EDA, Seaborn is faster. For custom publication-quality charts, Matplotlib gives more control. Most analysts use both together.

Logic

Intermediate

Q: What is the difference between copy() and a slice assignment in Pandas?

When you slice a DataFrame, you may get a "view" (reference to original) or a copy, depending on the operation. Modifying a view generates a SettingWithCopyWarning. To safely work on a subset, use df_subset = df[condition].copy() — this creates an independent DataFrame, and changes to it do not affect the original.

Advanced

Q: How do you use window functions in Pandas (rolling, cumsum, rank)?

Pandas equivalents of SQL window functions: df["rolling_avg"] = df["sales"].rolling(window=3).mean() (moving average), df["cumulative"] = df["sales"].cumsum() (running total), df["rank"] = df["sales"].rank(ascending=False) (ranking within the Series). These are vectorised and apply element-by-element without groupby.

df["3_month_avg"] = df["sales"].rolling(3).mean()
df["ytd_sales"] = df["sales"].cumsum()
df["rank"] = df["sales"].rank(method="dense", ascending=False)
Advanced

Q: How do you calculate a rank within groups using Pandas?

Use groupby combined with rank(): df["dept_rank"] = df.groupby("department")["salary"].rank(ascending=False). This gives each employee their rank within their own department — equivalent to SQL RANK() OVER (PARTITION BY department ORDER BY salary DESC).

df["dept_rank"] = df.groupby("department")["salary"].rank(ascending=False, method="min")
Advanced

Q: How do you find the top N rows per group in Pandas?

Sort the DataFrame, then use groupby with head(N): df.sort_values("sales", ascending=False).groupby("region").head(2). This gives the top 2 sales rows per region — equivalent to SQL ROW_NUMBER() OVER (PARTITION BY region ORDER BY sales DESC) with WHERE rank <= 2.

top2_per_region = (
    df.sort_values("sales", ascending=False)
    .groupby("region")
    .head(2)
)

Performance

Advanced

Q: How do you speed up Pandas operations on large datasets?

Key optimisations: (1) Use vectorised operations instead of apply() or loops; (2) Set appropriate dtypes — use category for low-cardinality string columns, int32 instead of int64 when values are small; (3) Use query() for filtering instead of boolean indexing for readability and speed; (4) Use chunked reading with chunksize in read_csv() for files too large to fit in memory; (5) Consider Polars or Dask for datasets exceeding available RAM.

About Python in Data Analyst Interviews

What Python topics are tested in data analyst interviews in India?

Indian data analyst interviews that include Python typically test: Pandas (DataFrame operations, groupby, merge, pivot_table), data cleaning (handling nulls, duplicates, type conversion), basic NumPy operations, Matplotlib/Seaborn for charts, and logic questions on list/dictionary manipulation. Product companies and startups test more deeply (EDA workflows, feature engineering); IT services firms often test basics only.

How important is Python for data analyst interviews in India?

Python is tested in approximately 40–50% of data analyst interviews in India in 2026 — primarily at product companies, startups, fintech, and senior-level roles. IT services companies (TCS, Infosys, Wipro, HCL) and BPO/KPO firms typically prioritise SQL and Power BI over Python for analyst roles. If you are targeting a product company or startup, Python is important. If you are targeting IT services for an entry-level role, focus SQL and Power BI first.

More Interview Prep

SQL Interview Questions India 2026
Window functions, JOINs, subqueries — what interviewers test
Power BI Interview Questions 2026
DAX, data modelling, RLS — most asked
Excel Interview Questions
Pivot tables, XLOOKUP, Power Query
General Data Analyst Interview Questions
HR + technical + case study rounds

EVIKA ACADEMY · NOIDA SECTOR 51 · PYTHON FOR DATA ANALYTICS

Learn Python the right way — live, with a trainer, not YouTube

Evening and weekend batches. Real datasets. Interview prep included. Free demo first.

Book Free Demo →