Python / Data Science Essentials Interview Questions
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 sns.set_theme(style='whitegrid', context='notebook') # --- 1. Load --- df = pd.read_csv('customer_orders.csv', parse_dates=['order_date']) # --- 2. Audit --- print(df.info()) print(df.isnull().sum()) print(df.describe()) # --- 3. Clean --- df = ( df .drop_duplicates(subset=['order_id']) .dropna(subset=['customer_id', 'amount']) .assign( amount=lambda d: pd.to_numeric(d['amount'], errors='coerce'), category=lambda d: d['category'].str.strip().str.title().astype('category'), year=lambda d: d['order_date'].dt.year, month=lambda d: d['order_date'].dt.month, ) .dropna(subset=['amount']) .query('amount > 0') ) # --- 4. Feature engineering (NumPy) --- amounts = df['amount'].to_numpy() df['log_amount'] = np.log1p(amounts) # log1p avoids log(0) df['amount_zscore'] = (amounts - amounts.mean()) / amounts.std() # --- 5. Aggregate --- monthly = ( df.groupby(['year', 'month', 'category']) .agg(total=('amount', 'sum'), orders=('order_id', 'count')) .reset_index() ) # --- 6. Visualise --- fig, axes = plt.subplots(1, 2, figsize=(14, 5)) # Revenue distribution by category sns.boxplot(data=df, x='category', y='log_amount', ax=axes[0]) axes[0].set(title='Log Revenue by Category', xlabel='', ylabel='log(1+amount)') # Monthly trend df['period'] = df['order_date'].dt.to_period('M').astype(str) trend = df.groupby('period')['amount'].sum().reset_index() axes[1].plot(trend['period'], trend['amount'], marker='o', linewidth=2) axes[1].tick_params(axis='x', rotation=45) axes[1].set(title='Monthly Revenue Trend', xlabel='Month', ylabel='Revenue') plt.tight_layout() plt.savefig('dashboard.png', dpi=150, bbox_inches='tight') plt.show()
The key integration patterns here: Pandas for all tabular operations (load, clean, aggregate), NumPy for numerical transformations on raw arrays (.to_numpy() → vectorised ops), and Seaborn/Matplotlib for visualisation. The method-chain style in the cleaning step makes the transformations readable as a pipeline.
More Related questions...