0% found this document useful (0 votes)
5 views4 pages

Python Mock Interview Questions

The document provides a guide on how to manipulate employee data using Pandas and NumPy in Python. It includes steps for loading a CSV file, analyzing data types, calculating averages, filtering employees, and performing various statistical operations. Additionally, it demonstrates how to use NumPy for array manipulation and boolean masking.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Python Mock Interview Questions

The document provides a guide on how to manipulate employee data using Pandas and NumPy in Python. It includes steps for loading a CSV file, analyzing data types, calculating averages, filtering employees, and performing various statistical operations. Additionally, it demonstrates how to use NumPy for array manipulation and boolean masking.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🟢 CSV → Pandas (You already covered)

(Keeping this for continuity)

emp_id,name,department,age,salary,experience,performance_score

101,Alice,HR,25,40000,2,3.5

102,Bob,IT,30,60000,5,4.2

103,Charlie,IT,35,65000,7,4.0

104,David,Finance,40,70000,10,3.8

105,Eva,HR,29,42000,3,3.6

106,Frank,IT,32,62000,6,4.5

107,Grace,Finance,45,80000,20,4.1

108,Helen,HR,28,45000,4,3.9

1️⃣ Load CSV

import pandas as pd
df = pd.read_csv("employee_data.csv")

2️⃣ First 5 rows

[Link]()

3️⃣ Data types

[Link]
4️⃣ Rows & Columns

[Link]

5️⃣ Null values

[Link]().sum()

🟡 Pandas Intermediate
6️⃣ Average salary

df["salary"].mean()

7️⃣ IT department employees

df[df["department"] == "IT"]

8️⃣ Average salary per department

[Link]("department")["salary"].mean()

9️⃣ Performance score > 4

df[df["performance_score"] > 4]

🔟 Sort by experience (descending)


df.sort_values(by="experience", ascending=False)
🔵 NumPy Questions (Based on Same
Data)
1️⃣ Convert salary column to NumPy array
import numpy as np
salary_arr = df["salary"].to_numpy()

2️⃣ Mean, Min, Max salary using NumPy


[Link](salary_arr)
[Link](salary_arr)
[Link](salary_arr)

3️⃣ Employees with salary above average (NumPy way)


avg_salary = [Link](salary_arr)
df[salary_arr > avg_salary]

4️⃣ Experience array & sorting (NumPy)


exp_arr = df["experience"].to_numpy()
[Link](exp_arr)

Descending:

[Link](exp_arr)[::-1]

5️⃣ Unique departments (NumPy)


[Link](df["department"])
6️⃣ Count employees per department (NumPy)
departments, counts = [Link](df["department"], return_counts=True)
dict(zip(departments, counts))

7️⃣ Salary standard deviation (NumPy)


[Link](salary_arr)

8️⃣ Boolean masking using NumPy

Employees with experience > 5 AND performance > 4:

mask = (df["experience"].to_numpy() > 5) &


(df["performance_score"].to_numpy() > 4)
df[mask]

9️⃣ Replace salary values < 50k with 50k (NumPy)


df["salary"] = [Link](df["salary"] < 50000, 50000, df["salary"])

🔟 Random sampling (NumPy)


Select random 3 employees:

[Link][[Link](len(df), 3, replace=False)]

You might also like