Post content
✅Python Interview Questions with Answers🧑💻👩💻 1️⃣ Write a function to remove outliers from a list using IQR. import numpy as np def remove_outliers(data): q1 = np.percentile(data, 25) q3 = np.percentile(data, 75) iqr = q3 - q1 lower = q1 - 1.5 * iqr upper = q3 + 1.5 * iqr return [x for x in data if lower <= x <= upper] 2️⃣ Convert a nested list to a flat list. nested = [[1, 2], [3, 4],] flat = [item for sublist in nested for item in sublist] 3️⃣ Read a CSV file and count rows with nulls. import pandas as pd df = pd.read_csv('data.csv') null_rows = df.isnull().any(axis=1).sum() print("Rows with nulls:", null_rows) 4️⃣ How do you handle missing data in pandas? ⦁ Drop missing rows: df.dropna() ⦁ Fill missing values: df.fillna(value) ⦁ Check missing data: df.isnull().sum() 5️⃣ Explain the difference between loc[] and iloc[]. ⦁ loc[]: Label-based indexing (e.g., row/column names) Example: df.loc[0, 'Name'] ⦁ iloc[]: Position-based indexing (e.g., row/column numbers) Example: df.iloc 💬Tap ❤️ for more!