15 Data Science Prompts for Analysis, Visualization, and Pandas Mastery

Introduction

The gap between raw data and actionable insight often feels like a chasm. Even with powerful tools like Pandas, Matplotlib, and Seaborn, knowing exactly what to ask of your data—and how to formulate that request as a clear, reproducible command—is a skill that separates proficient analysts from true experts. This article presents fifteen structured prompts designed to accelerate your data science workflow, from basic cleaning to advanced multivariate analysis. Each prompt is framed as a practical task, followed by a ready-to-use code snippet and a real-world example result. Whether you're wrangling customer transaction logs or exploring genomic datasets, these prompts will help you think in data structures, not just syntax.

1. Basic Prompts: Data Loading and Initial Exploration

Prompt 1: Load and Preview a Dataset

Task: Load a CSV file into a Pandas DataFrame and display its first five rows along with basic metadata.

Prompt:

import pandas as pd
df = pd.read_csv('sales_data.csv')
print(df.head())
print(df.info())

Example Result:

Column Non-Null Count Dtype
date 1000 object
revenue 1000 float64
region 980 object

This reveals 20 missing values in the region column and a date column stored as string, which requires conversion. This initial snapshot is the first step in any data science pipeline.

Prompt 2: Handle Missing Values

Task: Identify and impute missing values in numeric columns using the median.

Prompt:

missing_cols = df.columns[df.isnull().any()].tolist()
print('Missing columns:', missing_cols)
for col in df.select_dtypes(include='number').columns:
    if df[col].isnull().any():
        df[col].fillna(df[col].median(), inplace=True)

Example Result: Missing values in revenue and profit columns are replaced with median values, preserving distribution without introducing outliers. The dataset is now ready for analysis.

Prompt 3: Basic Statistical Summary

Task: Generate descriptive statistics for all numeric columns, grouped by a categorical variable.

Prompt:

df.groupby('region')['revenue'].describe()

Example Result:

region count mean std min max
East 350 1200.5 300.2 400 2500
West 300 1450.0 450.8 500 3200

The West region shows higher average revenue but also higher variability, suggesting potential for targeted growth strategies.

2. Intermediate Prompts: Transformation and Aggregation

Prompt 4: Date Parsing and Feature Extraction

Task: Convert a string date column to datetime and extract year, month, and day of week.

Prompt:

df['date'] = pd.to_datetime(df['date'])
df['year'] = df['date'].dt.year
df['month'] = df['date'].dt.month
df['dow'] = df['date'].dt.dayofweek  # Monday=0

Example Result: The new dow column enables analysis of weekend vs. weekday sales patterns. Many companies, for instance, see a 15–20% lift in e-commerce transactions on Fridays (source: Shopify 2024 trend report).

Prompt 5: Pivot Tables for Cross-Tabulation

Task: Create a pivot table showing average revenue by region and month.

Prompt:

pivot = pd.pivot_table(df, values='revenue', index='region', columns='month', aggfunc='mean')

Example Result:

region 1 2 3
East 1100 1300 1250
West 1400 1500 1450

This reveals consistent seasonal dips—useful for inventory planning.

Prompt 6: Conditional Aggregation with groupby and apply

Task: For each region, compute the percentage of high-value transactions (revenue > $2000).

Prompt:

def high_value_pct(group):
    return (group['revenue'] > 2000).mean() * 100
df.groupby('region').apply(high_value_pct)

Example Result: The West region has 22% high-value transactions, compared to 14% in the East. This insight can guide premium service allocation.

Prompt 7: Custom Function with transform

Task: Normalize revenue within each region using z-scores.

Prompt:

df['revenue_z'] = df.groupby('region')['revenue'].transform(lambda x: (x - x.mean()) / x.std())

Example Result: After transformation, outliers are immediately visible: any absolute z-score > 3 indicates a transaction that is statistically unusual. ASI Biont supports connecting to CRM systems via API to ingest such normalized metrics for anomaly detection—learn more at asibiont.com/courses.

3. Advanced Prompts: Visualization and Multivariate Analysis

Prompt 8: Correlation Heatmap with Seaborn

Task: Plot a correlation matrix for all numeric columns with annotations.

Prompt:

import matplotlib.pyplot as plt
import seaborn as sns
corr = df.select_dtypes(include='number').corr()
plt.figure(figsize=(10,8))
sns.heatmap(corr, annot=True, cmap='coolwarm', fmt='.2f')
plt.title('Correlation Heatmap of Sales Data')
plt.show()

Example Result: The heatmap shows revenue and profit have a correlation of 0.89, while revenue and discount have -0.45, confirming that discounts erode profit margin. This visualization is directly actionable for pricing strategy.

Prompt 9: Pairplot for Multivariate Exploration

Task: Create a pairplot colored by region to visually inspect clusters.

Prompt:

sns.pairplot(df, vars=['revenue', 'profit', 'quantity'], hue='region', diag_kind='kde')

Example Result: The pairplot reveals that the West region forms a distinct cluster with higher revenue and profit—an insight that would be missed in aggregate statistics.

Prompt 10: Time Series Decomposition

Task: Decompose a weekly revenue series into trend, seasonal, and residual components.

Prompt:

from statsmodels.tsa.seasonal import seasonal_decompose
series = df.set_index('date')['revenue'].resample('W').sum()
decomp = seasonal_decompose(series, model='additive', period=52)
decomp.plot()

Example Result: The seasonal component shows a clear Q4 spike each year, with a slight upward trend. The residual component highlights two anomalous weeks in March 2025—likely due to a marketing campaign.

Prompt 11: Outlier Detection with IQR and Visualization

Task: Flag outliers in revenue using the interquartile range (IQR) method and mark them on a boxplot.

Prompt:

Q1 = df['revenue'].quantile(0.25)
Q3 = df['revenue'].quantile(0.75)
IQR = Q3 - Q1
outliers = df[(df['revenue'] < Q1 - 1.5*IQR) | (df['revenue'] > Q3 + 1.5*IQR)]
print(f'Detected {len(outliers)} outliers')
sns.boxplot(x=df['revenue'])
plt.scatter(outliers['revenue'], [0]*len(outliers), color='red', label='Outliers')
plt.legend()

Example Result: 12 outliers are detected, all above the upper fence. Investigating these transactions reveals they are bulk corporate orders—a segment worth cultivating.

Prompt 12: Distribution Comparison with KDE and Histogram Overlay

Task: Compare the revenue distribution of two regions using overlapping histograms and KDE.

Prompt:

sns.histplot(data=df, x='revenue', hue='region', kde=True, alpha=0.5, bins=30)
plt.title('Revenue Distribution by Region')

Example Result: The West region's distribution is right-skewed, while the East's is roughly normal. This suggests different customer bases: West likely has a mix of high-value corporate clients and retail customers.

4. Expert Prompts: Performance and Automation

Prompt 13: Memory Optimization for Large Datasets

Task: Downcast numeric columns to reduce memory usage by up to 50%.

Prompt:

def optimize_memory(df):
    for col in df.select_dtypes(include=['int64', 'float64']).columns:
        c_min, c_max = df[col].min(), df[col].max()
        if df[col].dtype == 'int64':
            if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:
                df[col] = df[col].astype(np.int8)
            # similar checks for int16, int32
        else:
            if c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:
                df[col] = df[col].astype(np.float32)
    return df

Example Result: Memory usage drops from 2.1 GB to 800 MB on a dataset with 5 million rows. This is critical when working in memory-constrained environments like AWS Lambda or local machines.

Prompt 14: Parallel Processing with pandas and swifter

Task: Apply a complex function to each row using multiple cores.

Prompt:

import swifter
df['processed'] = df.swifter.apply(lambda row: some_complex_function(row), axis=1)

Example Result: On a 4-core machine, processing time decreases from 12 seconds to 3.8 seconds. The swifter library automatically chooses the fastest vectorized or parallel method.

Prompt 15: Automated Data Profiling with ydata-profiling

Task: Generate a comprehensive HTML report with correlations, missing values, and distribution plots.

Prompt:

from ydata_profiling import ProfileReport
profile = ProfileReport(df, title='Sales Data Profiling Report', explorative=True)
profile.to_file('report.html')

Example Result: The report includes 25+ interactive charts, alerts for high cardinality columns, and a correlation heatmap. It's an excellent deliverable for stakeholder review.

Real-World Case Study: E-Commerce Revenue Analysis

Problem: A mid-sized online retailer noticed a plateau in revenue growth but had no clear explanation from raw transaction logs. The dataset contained 200,000 rows with columns: date, customer_id, revenue, discount, region, product_category.

Solution: Using prompts 1–8 from this collection, the analyst:
- Loaded and cleaned the data (prompts 1–3)
- Extracted temporal features and identified a Saturday peak (prompt 4)
- Built a pivot table showing that the Electronics category had 40% higher revenue but also 55% higher discount usage (prompt 5)
- Applied conditional aggregation to discover that 70% of high-value transactions came from returning customers in the West region (prompt 6)
- Created a correlation heatmap (prompt 8) that revealed a strong negative correlation (-0.72) between discount percentage and profit margin

Result: The retailer reduced discounts on electronics by 15%, which led to a 9% increase in overall profit margin over the next quarter without losing transaction volume.

Key Takeaway: The combination of basic cleaning, groupby aggregation, and multivariate visualization provided a cohesive narrative that raw SQL queries could not match.

Conclusion

Mastering data science prompts means internalizing a structured approach: start with exploration, move to transformation, then visualize and model. The fifteen prompts above cover the full spectrum from loading a CSV to generating a professional profiling report. By practicing these patterns, you will not only write more efficient code but also ask sharper questions of your data. The next time you receive a new dataset, begin with prompt 1—your future self will thank you.

Remember, the best prompt is the one that turns a vague business question into a precise DataFrame operation. Happy analyzing!

← All posts

Comments