🐼 1.
pandas
Definition: pandas is used for data manipulation and analysis. It provides powerful data structures
like Series (1D) and DataFrame (2D).
import pandas as pd
# Create a simple DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35]
df = [Link](data)
print(df)
🔢 2. NumPy
Definition: NumPy is used for numerical computations with support for arrays and matrices.
import numpy as np
# Create an array
arr = [Link]([1, 2, 3, 4, 5])
# Multiply each element by 2
result = arr * 2
print(result)
📈 3. Matplotlib
Definition: Matplotlib is a plotting library for creating static, animated, and interactive visualizations.
import [Link] as plt
# Data
x = [1, 2, 3, 4, 5]
y = [10, 20, 25, 30, 40]
# Plot
[Link](x, y)
[Link]("Line Graph")
[Link]("X-axis")
[Link]("Y-axis")
[Link]()
🔬 4. SciPy
Definition: SciPy builds on NumPy and provides functions for scientific and technical computing, like
integration and optimization.
from scipy import stats
data = [1,3,5,7,9]
mean = [Link](data)
std_dev = [Link](data)
print("Mean = ", mean)
print("Std = ", std_dev)
🤖 5. scikit-learn
Definition: scikit-learn is a machine learning library that provides tools for modeling, classification,
regression, and clustering.
from sklearn.linear_model import LinearRegression
# Sample data
X = [[1], [2], [3], [4]] # Feature (independent
variable)
y = [2, 4, 6, 8] # Target (dependent variable)
# Create and train model
model = LinearRegression()
[Link](X, y)
# Predict
prediction = [Link]([[5]])
print("Prediction for input 5:", prediction[0])
🔁 1. while Loop
Definition: Repeats a block of code as long as a condition is True.
i=1
while i <= 5:
print(i)
🔁 2. for Loop
i += 1
Definition: Iterates over a sequence (like list, tuple, or string).
fruits = ['apple', 'banana', 'cherry']
for fruit in fruits:
print(fruit)
✅ 3. if Statement
Definition: Executes a block only if a condition is True.
num = 0
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
🧩 4. else Statement
Definition: Runs if all if and elif conditions are False.
num = 0
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
✅ List of Graphs in Matplotlib
📈 Graph Type 🧾 Description
plot() Line graph – to show trends over time
scatter() Scatter plot – for correlation or distribution
bar() / barh() Bar chart / Horizontal bar chart
hist() Histogram – for frequency distribution
pie() Pie chart – to show percentages/proportions
boxplot() Box plot – for summary stats like median, quartiles
stem() Stem plot – to display discrete data
stackplot() Stacked area chart – for multiple data series over time
area() (custom) Area chart (can be created using fill_between())
errorbar() Error bars – to show variability
violinplot() Violin plot – like box plot but shows distribution shape
hexbin() Hexbin plot – for 2D histogram using hexagons
imshow() / matshow() For displaying images or matrices
contour() / contourf() Contour plots – for 3D surface data on 2D
quiver() Vector field plots
3D plots Using mpl_toolkits.mplot3d module for surface, wireframe, etc.
polar() Polar plots – data in polar coordinates
eventplot() Event plot – time-based events
step() Step plot – like line plot but with steps
Tool/Language Core Concepts to Learn
- Data types (int, float, string, list, dict, tuple)
- Conditional statements (if, elif, else)
- Loops (for, while)
- Functions
Python - File handling (read/write CSV, Excel)
- Libraries: pandas, numpy, matplotlib, seaborn
- Data cleaning & preprocessing
- Exploratory Data Analysis (EDA)
- Basics: SELECT, WHERE, ORDER BY, LIMIT
- Filtering data (LIKE, IN, BETWEEN)
- Aggregate functions (COUNT, SUM, AVG, MIN, MAX)
SQL - GROUP BY and HAVING
- JOINs (INNER, LEFT, RIGHT, FULL)
- Subqueries
- Creating and updating tables (DDL & DML basics)
- Cell referencing (absolute, relative)
- Basic formulas: SUM, AVERAGE, IF, COUNTIF,
VLOOKUP/XLOOKUP
- Data cleaning (Remove duplicates, Text-to-columns)
MS Excel
- Sorting and filtering
- Pivot Tables & Pivot Charts
- Conditional formatting
- Creating basic dashboards
- Connecting to data sources
- Data transformation with Power Query
- Creating visualizations (bar, pie, line, map)
Power BI - Basic DAX functions (SUM, COUNT, CALCULATE)
- Creating relationships between tables
- Creating interactive dashboards
- Publishing reports to Power BI Service
Excel Questions (Basic to Advanced)
1. Basic Excel Functions and Operations:
o What is Excel, and what are some basic features of Excel?
o How do you format cells in Excel?
o How can you adjust the size of a row or column?
o What is the difference between absolute, relative, and mixed references in Excel?
o How do you freeze panes in Excel?
o Can you explain what a cell range is and how to use it in formulas?
o How do you insert a chart in Excel?
o What is the shortcut to select an entire row/column?
o How do you find and replace text in Excel?
o What are named ranges, and how are they useful?
o How can you add a drop-down list in a cell in Excel?
2. Intermediate Functions:
o What is VLOOKUP, and how is it used?
o What is HLOOKUP, and how is it different from VLOOKUP?
o Can you explain the IF function? Provide an example.
o What is the SUMIF function, and when would you use it?
o How do you use the COUNTIF function?
o What are the differences between COUNT, COUNTA, and COUNTBLANK?
o How do you use the CONCATENATE function or its modern equivalent (TEXTJOIN)?
o How do you perform conditional formatting in Excel?
o How do you use pivot tables in Excel?
o What are slicers in PivotTables, and how do you use them?
3. Advanced Functions and Data Handling:
o What is INDEX-MATCH, and how does it work together?
o Explain the use of the SUMPRODUCT function.
o How do you deal with errors in Excel (e.g., #N/A, #REF, #DIV/0)?
o What is a dynamic named range, and how do you create one?
o How do you use Power Query in Excel?
o What are macros, and how do you record one in Excel?
o Can you explain the process of creating a dashboard in Excel?
o How do you use the TEXT function to format dates or numbers in Excel?
4. Data Analysis Techniques:
o How do you perform data cleaning in Excel?
o Explain how you can find duplicates in Excel.
o How do you handle large datasets (e.g., sorting, filtering, or removing duplicates)?
o What is the Solver tool in Excel, and how would you use it for optimization
problems?
o How do you split text into columns in Excel?
o What is the difference between a PivotTable and a regular table in Excel?
Python Questions (Basic to Advanced)
1. Basic Python Syntax and Functions:
o What is Python, and what are some features that make it popular for data analysis?
o What are the differences between a list and a tuple in Python?
o What is a dictionary in Python, and how do you use it?
o How do you define a function in Python?
o What is the purpose of the return statement in Python functions?
o What is the difference between == and is in Python?
o How do you handle strings in Python (e.g., concatenation, slicing)?
o What is the purpose of the if statement in Python?
o How do you loop through a list in Python?
2. Data Structures and Libraries:
o What are lists, sets, and dictionaries, and when would you use each?
o How do you create and manipulate Pandas DataFrames in Python?
o What are NumPy arrays, and how are they different from Python lists?
o How do you load data into a DataFrame using Pandas?
o How do you filter data in a Pandas DataFrame?
o What is the difference between .loc[] and .iloc[] in Pandas?
o How do you merge two DataFrames in Pandas?
o How do you handle missing data in Pandas?
o What is the purpose of apply() in Pandas?
3. Data Analysis and Visualization:
o How do you group data by specific columns in Pandas?
o What are some common methods for data visualization in Python (e.g., Matplotlib,
Seaborn)?
o How do you create a basic plot using Matplotlib?
o How do you visualize a correlation matrix in Python?
o How do you use seaborn for creating plots (e.g., box plots, histograms)?
o How do you handle date and time data in Python (e.g., datetime, timedelta)?
o How do you calculate the mean, median, mode, and standard deviation in Python?
o How would you clean a dataset in Python?
4. Advanced Topics and Concepts:
o What are lambda functions in Python, and how are they used?
o Explain what list comprehensions are and provide an example.
o What is object-oriented programming (OOP) in Python, and how does it work?
o How do you implement error handling using try-except blocks in Python?
o How do you use the filter() function in Python?
o What are Python decorators and how do they work?
o Explain what Python generators are and how they differ from regular functions.
Power BI Questions (Basic to Advanced)
1. Basic Power BI Features:
o What is Power BI, and how does it differ from Excel?
o How do you import data into Power BI?
o What are the different types of visualizations in Power BI?
o What is the purpose of Power Query in Power BI?
o How do you filter data in Power BI reports?
o How do you create a simple chart (e.g., bar chart, line chart) in Power BI?
o What is a slicer, and how do you use it in Power BI?
2. Data Transformation and Cleaning:
o How do you clean data in Power BI using Power Query?
o How do you split columns in Power BI?
o What are joins in Power BI, and how are they used?
o How do you remove duplicates in Power BI?
o How do you handle missing data in Power BI?
3. Power BI Data Modeling:
o What is data modeling in Power BI, and why is it important?
o How do you create relationships between tables in Power BI?
o What is a star schema and snowflake schema in Power BI?
o How do you create calculated columns and measures in Power BI?
o What is DAX (Data Analysis Expressions) in Power BI?
o How do you use basic DAX functions like SUM, AVERAGE, and COUNT?
o How do you use time intelligence functions in DAX?
o What is the difference between a calculated column and a measure in Power BI?
4. Advanced Power BI Features:
o How do you create a dynamic report in Power BI?
o How do you implement row-level security in Power BI?
o What are drill-down and drill-through in Power BI, and how do you use them?
o How do you implement bookmarks and storytelling in Power BI?
o How do you integrate Power BI with other services like Excel, SharePoint, or SQL
Server?
o How do you publish and share reports in Power BI?
Miscellaneous and Basic Understanding:
What is the difference between structured and unstructured data?
What are the key steps in data analysis?
How would you explain the process of cleaning data?
What is ETL (Extract, Transform, Load)?
How do you handle large datasets (e.g., performance optimization)?
What are the differences between OLTP and OLAP databases?
How do you ensure the accuracy and reliability of data in analysis?
1. Basic SQL Concepts:
Q1: What is SQL?
Answer: SQL (Structured Query Language) is a programming language used to manage and
manipulate relational databases. It is used for tasks such as querying, updating, inserting,
and deleting data from a database.
Q2: What are the basic SQL commands?
Answer: The basic SQL commands are:
o SELECT – Used to retrieve data from a database.
o INSERT INTO – Used to insert data into a table.
o UPDATE – Used to modify existing data.
o DELETE – Used to remove data from a table.
o CREATE – Used to create new tables or databases.
o ALTER – Used to modify an existing database object.
o DROP – Used to delete tables, databases, or other objects.
Q3: What is a database and a table?
Answer: A database is an organized collection of data. A table is a collection of rows and
columns used to store the data in a relational database.
Q4: What is a primary key?
Answer: A primary key is a unique identifier for a record in a table. Each table can only have
one primary key, and it ensures that no two rows have the same value in that column.
Q5: What is a foreign key?
Answer: A foreign key is a column or group of columns in a table that links to the primary
key in another table. It establishes a relationship between the two tables.
Q6: What is the difference between WHERE and HAVING clauses?
Answer:
o The WHERE clause is used to filter records before any grouping is done (applies to
individual rows).
o The HAVING clause is used to filter records after grouping is done (applies to groups).
2. Data Retrieval and Filtering:
Q7: How do you retrieve all columns from a table?
Answer:
sql
CopyEdit
SELECT * FROM table_name;
Q8: How do you retrieve specific columns from a table?
Answer:
sql
CopyEdit
SELECT column1, column2 FROM table_name;
Q9: What is the DISTINCT keyword?
Answer: The DISTINCT keyword is used to return only unique (different) values in a column.
sql
CopyEdit
SELECT DISTINCT column_name FROM table_name;
Q10: How do you filter data using the WHERE clause?
Answer:
sql
CopyEdit
SELECT * FROM table_name WHERE condition;
Q11: What are logical operators in SQL?
Answer: Logical operators allow you to combine multiple conditions in the WHERE clause:
o AND – Returns true if all conditions are true.
o OR – Returns true if at least one condition is true.
o NOT – Reverses the result of a condition.
3. Sorting and Grouping Data:
Q12: How do you sort data in SQL?
Answer:
sql
CopyEdit
SELECT * FROM table_name ORDER BY column_name [ASC|DESC];
ASC is the default (ascending order), and DESC sorts in descending order.
Q13: What is the GROUP BY clause?
Answer: The GROUP BY clause is used to group rows that have the same values into
summary rows, like finding the total or average.
sql
CopyEdit
SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name;
Q14: What is the COUNT() function?
Answer: The COUNT() function returns the number of rows that match a specified condition.
sql
CopyEdit
SELECT COUNT(*) FROM table_name WHERE condition;
Q15: What is the SUM() function?
Answer: The SUM() function returns the total sum of a numeric column.
sql
CopyEdit
SELECT SUM(column_name) FROM table_name;
Q16: What is the AVG() function?
Answer: The AVG() function returns the average value of a numeric column.
sql
CopyEdit
SELECT AVG(column_name) FROM table_name;
Q17: How do you use GROUP BY with aggregate functions?
Answer: You can group data and perform aggregate calculations (e.g., COUNT, SUM, AVG) on
each group.
sql
CopyEdit
SELECT column_name, COUNT(*), SUM(column2) FROM table_name GROUP BY column_name;
4. Joining Tables:
Q18: What is a JOIN in SQL?
Answer: A JOIN is used to combine rows from two or more tables based on a related column
between them.
Q19: What is an INNER JOIN?
Answer: An INNER JOIN returns only the rows where there is a match in both tables.
sql
CopyEdit
SELECT * FROM table1 INNER JOIN table2 ON [Link] = [Link];
Q20: What is a LEFT JOIN (or LEFT OUTER JOIN)?
Answer: A LEFT JOIN returns all rows from the left table and the matching rows from the
right table. If no match is found, NULL is returned for columns from the right table.
sql
CopyEdit
SELECT * FROM table1 LEFT JOIN table2 ON [Link] = [Link];
Q21: What is a RIGHT JOIN (or RIGHT OUTER JOIN)?
Answer: A RIGHT JOIN returns all rows from the right table and the matching rows from the
left table. If no match is found, NULL is returned for columns from the left table.
sql
CopyEdit
SELECT * FROM table1 RIGHT JOIN table2 ON [Link] = [Link];
Q22: What is a FULL JOIN (or FULL OUTER JOIN)?
Answer: A FULL JOIN returns all rows when there is a match in either the left or right table. If
no match is found, NULLs are returned for non-matching rows.
sql
CopyEdit
SELECT * FROM table1 FULL JOIN table2 ON [Link] = [Link];
Q23: What is a CROSS JOIN?
Answer: A CROSS JOIN returns the Cartesian product of two tables (every combination of
rows from both tables).
sql
CopyEdit
SELECT * FROM table1 CROSS JOIN table2;
5. Subqueries and Nested Queries:
Q24: What is a subquery?
Answer: A subquery is a query within another query, used to retrieve data that will be used
in the main query.
sql
CopyEdit
SELECT * FROM table_name WHERE column IN (SELECT column FROM another_table);
Q25: What is a correlated subquery?
Answer: A correlated subquery refers to a subquery that uses values from the outer query.
sql
CopyEdit
SELECT * FROM table1 t1 WHERE [Link] IN (SELECT [Link] FROM table2 t2 WHERE [Link]
= [Link]);
6. Modifying Data:
Q26: How do you insert data into a table?
Answer:
sql
CopyEdit
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
Q27: How do you update data in a table?
Answer:
sql
CopyEdit
UPDATE table_name SET column1 = value1 WHERE condition;
Q28: How do you delete data from a table?
Answer:
sql
CopyEdit
DELETE FROM table_name WHERE condition;
7. Data Integrity and Constraints:
Q29: What are constraints in SQL?
Answer: Constraints are rules applied to columns in a table to ensure the integrity of the
data. Common constraints include:
o NOT NULL – Ensures a column cannot have NULL values.
o UNIQUE – Ensures all values in a column are unique.
o CHECK – Ensures that all values in a column satisfy a specific condition.
o DEFAULT – Provides a default value for a column when no value is provided.
o PRIMARY KEY – Uniquely identifies each row in a table.
o FOREIGN KEY – Ensures referential integrity by linking to the primary key of another
table.
Q30: What is normalization?
Answer: Normalization is the process of organizing data in a database to reduce redundancy
and improve data integrity. The process involves dividing large tables into smaller ones and
defining relationships between them.
Q31: What are the different normal forms in database normalization?
Answer: The common normal forms are:
o 1NF (First Normal Form) – Eliminate duplicate columns, ensure atomicity (values are
indivisible).
o 2NF (Second Normal Form) – Meet 1NF, and all non-key attributes are fully
dependent on the primary key.
o 3NF (Third Normal Form) – Meet 2NF, and no transitive dependency exists.
8. Advanced SQL Concepts:
Q32: What are window functions in SQL?
Answer: Window functions perform calculations across a set of table rows related to the
current row. They are used with the OVER() clause. Examples include ROW_NUMBER(),
RANK(), DENSE_RANK(), LEAD(), and LAG().
Q33: What is indexing in SQL?
Answer: Indexing is a technique used to speed up the retrieval of rows from a database
table. An index creates a data structure that improves query performance, especially for
searches on large tables.
Q34: What is a transaction in SQL?
Answer: A transaction is a sequence of SQL statements that are executed as a single unit. It
ensures that either all operations are completed successfully, or none are applied
(atomicity). SQL commands involved in transactions include COMMIT, ROLLBACK, and
SAVEPOINT.
These questions and answers should provide a solid foundation to prepare for SQL-based data
analyst interviews.
2/2
4o mini
You said:
Cte,Sub queries,Partition,Rank, dense rank, row number >> are these involved in above if not involve
them also
ChatGPT said:
You're absolutely right! Some key concepts like CTE (Common Table Expressions), Subqueries,
Partitioning, Ranking Functions (RANK, DENSE_RANK, ROW_NUMBER) were not fully covered in the
previous answer, and these are important aspects in SQL for a data analyst role. Let's dive into these
topics in more detail.
9. Advanced SQL Concepts (Continued)
Common Table Expressions (CTE)
Q1: What is a Common Table Expression (CTE)?
Answer: A CTE is a temporary result set that can be referenced within a SELECT, INSERT,
UPDATE, or DELETE statement. It is defined using the WITH clause and can be used to
simplify complex queries by breaking them into smaller, more manageable parts.
Example:
sql
CopyEdit
WITH CTE AS (
SELECT column1, column2 FROM table_name WHERE condition
SELECT * FROM CTE;
Q2: Why would you use a CTE over a subquery?
Answer: CTEs make the query easier to read and maintain, especially when working with
recursive queries. They can also improve query performance in certain cases by avoiding the
repetition of complex logic.
Subqueries
Q3: What is a subquery in SQL?
Answer: A subquery is a query nested inside another query. Subqueries are used to return
data that will be used by the outer query.
Q4: Can you give an example of a subquery in SQL?
Answer:
sql
CopyEdit
SELECT column_name
FROM table_name
WHERE column_name IN (
SELECT column_name
FROM another_table
WHERE condition
);
Q5: What are the types of subqueries?
Answer:
o Single-row subqueries: Return a single row and are used with operators like =, <, >.
o Multiple-row subqueries: Return more than one row and are used with operators
like IN, ANY, ALL.
o Correlated subqueries: Refer to columns from the outer query, unlike standard
subqueries which are independent of the outer query.
Partitioning and Window Functions
Q6: What is the PARTITION BY clause in SQL?
Answer: The PARTITION BY clause is used with window functions to divide the result set into
partitions (groups of rows). Each partition is processed separately for the calculation of the
window function.
Example:
sql
CopyEdit
SELECT column1,
SUM(column2) OVER (PARTITION BY column3) AS partition_sum
FROM table_name;
Q7: What are window functions in SQL?
Answer: Window functions allow you to perform calculations across a set of rows related to
the current row, like calculating sums, averages, or ranks, without having to group the data
into aggregate results.
Window functions are used with the OVER() clause, which may also include PARTITION BY (for
dividing rows into groups) and ORDER BY (to define the order within each partition).
Ranking Functions
Q8: What is the RANK() function in SQL?
Answer: The RANK() function assigns a rank to each row within a partition of a result set. If
two rows have the same value, they will receive the same rank, but the next rank will be
skipped.
Example:
sql
CopyEdit
SELECT column1,
RANK() OVER (PARTITION BY column2 ORDER BY column3 DESC) AS rank
FROM table_name;
Output Example:
Less
CopyEdit
column1 | rank
----------------
A |1
B |2
B |2
C |4
Q9: What is the DENSE_RANK() function in SQL?
Answer: The DENSE_RANK() function also assigns a rank to each row, but unlike RANK(), it
does not skip ranks when there are ties.
Example:
sql
CopyEdit
SELECT column1,
DENSE_RANK() OVER (PARTITION BY column2 ORDER BY column3 DESC) AS dense_rank
FROM table_name;
Output Example:
less
CopyEdit
column1 | dense_rank
---------------------
A |1
B |2
B |2
C |3
Q10: What is the ROW_NUMBER() function in SQL?
Answer: The ROW_NUMBER() function assigns a unique sequential integer to rows within a
partition, without any gaps in the numbering, even if there are ties in the data.
Example:
sql
CopyEdit
SELECT column1,
ROW_NUMBER() OVER (PARTITION BY column2 ORDER BY column3 DESC) AS row_number
FROM table_name;
Output Example:
less
CopyEdit
column1 | row_number
---------------------
A |1
B |2
B |3
C |4
Practical Examples with Partitioning and Ranking
Q11: How would you find the top 3 highest salaries in each department using ROW_NUMBER()?
Answer:
sql
CopyEdit
WITH RankedSalaries AS (
SELECT department_id, salary,
ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rank
FROM employees
SELECT department_id, salary
FROM RankedSalaries
WHERE rank <= 3;
Q12: How would you get the second highest salary in each department using RANK() or
DENSE_RANK()?
Answer (using RANK()):
sql
CopyEdit
WITH RankedSalaries AS (
SELECT department_id, salary,
RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rank
FROM employees
SELECT department_id, salary
FROM RankedSalaries
WHERE rank = 2;
CTEs, Subqueries, Partitioning, Ranking Functions in SQL (Summarized)
Here’s a quick recap of the advanced topics mentioned:
1. CTE (Common Table Expressions): A temporary result set defined with WITH for complex
queries and recursion.
2. Subqueries: Queries nested inside another query, used to provide data for the outer query.
3. Partitioning (PARTITION BY): Dividing the result set into partitions for window functions like
RANK, DENSE_RANK, ROW_NUMBER.
4. Ranking Functions:
o RANK(): Assigns a rank with gaps in the sequence for ties.
o DENSE_RANK(): Assigns a rank without gaps in the sequence for ties.
o ROW_NUMBER(): Assigns a unique sequential number to rows, regardless of ties.
These advanced SQL concepts allow for more powerful, efficient, and organized data analysis,
especially when working with large datasets and complex queries.