10 Prompts for Data Science: Pandas, Visualization, and Analysis

10 Prompts for Data Science: Pandas, Visualization, and Analysis

Introduction

Strong data science depends on clean questions as much as clean code. Large language models can help you explore DataFrames, but vague prompts produce generic answers. This guide collects 10 battle-tested prompts for Pandas, Matplotlib, and Seaborn. They automate profiling, cleaning, visualization, and modeling preparation. For background, see the Pandas User Guide (pandas.pydata.org), Matplotlib docs, and the Python Data Science Handbook.

1. Data Profiling in One Shot

Use case: You just loaded a dataset and need a quick overview.
Prompt:

You are a data analyst. Write pandas code to print shape, dtypes, memory usage, missing values, unique counts, and descriptive statistics for df. Group results in a readable format.
Code:

df.info()
df.isnull().mean()
df.nunique()
df.describe(include='all')

Use this as your first step after loading any CSV.

2. Robust Missing-Value Pipeline

Use case: Numeric columns have missing values; you need safe imputation.
Prompt:

Build a cleaning pipeline using median imputation for numeric columns and drop_duplicates. Explain why median is preferred for skewed data, and avoid inplace=True by reassigning.
Code:

num_cols = df.select_dtypes(include='number').columns
df[num_cols] = df[num_cols].fillna(df[num_cols].median())
df = df.drop_duplicates()

Median is less sensitive to outliers than mean—key for real-world datasets.

3. Feature Engineering from Dates

Use case: Need to extract time-based features.
Prompt:

Create a function that takes a DataFrame with a date column and returns year, month, week, weekday name, and a flag for weekends. Apply it with assign and show the new columns.
Code:

df = df.assign(
    year=df['date'].dt.year,
    month=df['date'].dt.month,
    weekday=df['date'].dt.day_name(),
    is_weekend=df['date'].dt.weekday >= 5
)

Time-based features often improve model accuracy.

4. Multi-Panel Matplotlib Exploration

Use case: Inspect distributions and outliers visually.
Prompt:

Make a 2x2 matplotlib figure: histogram with KDE, boxplot, Q-Q plot, and scatter of two most correlated numeric columns. Add titles and tight_layout.
Code:

import matplotlib.pyplot as plt
from scipy import stats
fig, ax = plt.subplots(2, 2)
ax[0,0].hist(df['price'], bins=30, density=True)
df['price'].plot.kde(ax=ax[0,0])
ax[0,1].boxplot(df['price'])
stats.probplot(df['price'], plot=ax[1,0])
ax[1,1].scatter(df['price'], df['sqft'])
plt.tight_layout()

Adapt column names to your data.

5. Seaborn Category Comparison

Use case: Compare a metric across groups.
Prompt:

Create a violin plot with a boxplot overlay and a swarmplot of actual points using seaborn. Add a caption that explains the practical difference between groups.
Code:

import seaborn as sns
sns.violinplot(data=df, x='group', y='metric')
sns.boxplot(data=df, x='group', y='metric', width=0.1)
sns.swarmplot(data=df, x='group', y='metric', color='black', size=2)

Violin plots reveal multimodal distributions that boxplots miss.

6. Correlation Heatmap with Context

Use case: Find relationships before modeling.
Prompt:

Compute Spearman and Pearson correlation matrices for numeric columns with pairwise deletion. Show a heatmap with annotated values. Explain in one paragraph when each correlation type is appropriate.
Code:

pearson = df.corr(method='pearson')
spearman = df.corr(method='spearman')
sns.heatmap(spearman, annot=True, cmap='coolwarm')

Spearman handles monotonic non-linear relationships while Pearson measures linear only.

7. Pivot Table Summary

Use case: Summarize metrics by two keys.
Prompt:

Build a pivot table with region as rows and product as columns, showing mean revenue and count of orders. Also provide the equivalent groupby().agg() code.
Code:

pd.pivot_table(df, index='region', columns='product',
               values='revenue', aggfunc=['mean', 'count'])

Pivot tables are ideal for business dashboards.

8. Time Series Resampling

Use case: Convert irregular sensor data to daily/weekly.
Prompt:

Resample a datetime-indexed DataFrame to daily mean and weekly last, forward-fill missing days, and show how to handle time zones with utc=True.
Code:

daily = df.resample('D').mean().ffill()
weekly = df.resample('W').last()

Always inspect empty periods when resampling.

9. Missing Data Report Generator

Use case: Automate missingness analysis.
Prompt:

Write a function that returns a DataFrame with missing percentage per column, sorted descending, and a horizontal bar chart. Add a rule: if missing > 5%, suggest drop; otherwise, impute.
Code:

def missing_report(df):
    report = (df.isnull().mean().sort_values(ascending=False) * 100)
    report.plot.barh(title='Missing % by column')
    return report

This report is useful when starting with messy data.

10. Model-Ready Train/Test Split

Use case: Prepare a reliable validation setup.
Prompt:

Split a DataFrame into train and test for classification with train_test_split, using stratify and random_state. Scale features with StandardScaler after the split and explain why scaling before splitting leaks information.
Code:

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, stratify=y, random_state=42)
scaler = StandardScaler().fit(X_train)
X_train_s = scaler.transform(X_train)
X_test_s = scaler.transform(X_test)

Fit the scaler on train only to avoid data leakage.

Conclusion

These 10 prompts give you a reusable toolkit for exploratory data science. Use them as a starting point, then customize the instructions with your column names and domain context. The best prompt is the one that makes you think about your data. Put this list in your notebook and start exploring.

← All posts

Comments