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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
