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

Introduction

Data science is as much about asking the right questions as it is about writing code. The real skill lies in translating business problems into precise, reproducible data manipulations. Over the past decade, Python's Pandas library has become the de facto tool for data wrangling, while Matplotlib and Seaborn remain the workhorses for visualization. But even experienced analysts sometimes waste hours crafting the perfect transformation or debugging a plot. This is where structured prompts come in: they act as mental scaffolds, turning vague requests into actionable code. In this article, I share 15 carefully designed prompts for data analysis, Pandas operations, and visualization that will save you time and reduce errors. Each prompt includes a concrete example so you can see the result immediately.

Whether you are cleaning messy survey data, building financial dashboards, or preparing a report for stakeholders, these prompts will help you work faster and more confidently.

1. Basic Prompts: Data Loading and Inspection

Prompt 1: Load Data and Display Summary Statistics

  • Task: Load a CSV file, show the first five rows, and print descriptive statistics for all numeric columns.
  • Prompt: "Load the file sales.csv into a Pandas DataFrame, display the head, and call describe() on the numeric columns."
  • Example:
import pandas as pd

df = pd.read_csv('sales.csv')
print(df.head())
print(df.describe())

Prompt 2: Check for Missing Values

  • Task: Identify which columns contain null values and count them.
  • Prompt: "Count missing values per column in df and list columns with more than 5% missing."
  • Example:
missing = df.isnull().sum()
missing_percent = (missing / len(df)) * 100
print(missing[missing > 0])
print(missing_percent[missing_percent > 5])

Prompt 3: Filter Rows Based on Condition

  • Task: Return all rows where the revenue column exceeds 1000 and the region is 'Europe'.
  • Prompt: "Filter df for rows where revenue > 1000 and region == 'Europe'."
  • Example:
filtered = df[(df['revenue'] > 1000) & (df['region'] == 'Europe')]
print(filtered.head())

2. Intermediate Prompts: Data Transformation with Pandas

Prompt 4: Group By and Aggregate

  • Task: Group data by category and calculate sum, mean, and count for sales.
  • Prompt: "Group df by category and compute sum, mean, and count of sales."
  • Example:
grouped = df.groupby('category')['sales'].agg(['sum', 'mean', 'count'])
print(grouped)

Prompt 5: Apply a Custom Function to a Column

  • Task: Create a new column price_category that labels values as 'low', 'medium', or 'high' based on quantiles.
  • Prompt: "Add a column price_category using pd.cut with three equal-width bins on price."
  • Example:
df['price_category'] = pd.cut(df['price'], bins=3, labels=['low', 'medium', 'high'])
print(df[['price', 'price_category']].head())

Prompt 6: Merge Two DataFrames on a Key

  • Task: Combine orders and customers DataFrames on customer_id using a left join.
  • Prompt: "Merge orders with customers on customer_id using a left join."
  • Example:
merged = pd.merge(orders, customers, on='customer_id', how='left')
print(merged.head())

Prompt 7: Pivot Table for Summary Matrix

  • Task: Create a pivot table showing average revenue per region and product category.
  • Prompt: "Build a pivot table from df with region as index, category as columns, and revenue as values using mean."
  • Example:
pivot = pd.pivot_table(df, values='revenue', index='region', columns='category', aggfunc='mean')
print(pivot)

3. Advanced Prompts: Visualization with Matplotlib and Seaborn

Prompt 8: Histogram with Custom Bins

  • Task: Plot the distribution of age with 30 bins and a Kernel Density Estimate (KDE) overlay.
  • Prompt: "Use Seaborn's histplot to show distribution of age with 30 bins and KDE."
  • Example:
import seaborn as sns
import matplotlib.pyplot as plt

sns.histplot(df['age'], bins=30, kde=True)
plt.title('Age Distribution')
plt.show()

Prompt 9: Box Plot to Detect Outliers

  • Task: Compare salary distributions across department using a box plot.
  • Prompt: "Create a Seaborn box plot with department on x-axis and salary on y-axis."
  • Example:
sns.boxplot(x='department', y='salary', data=df)
plt.title('Salary by Department')
plt.xticks(rotation=45)
plt.show()

Prompt 10: Correlation Heatmap

  • Task: Compute and visualize correlation matrix for numeric columns.
  • Prompt: "Plot a heatmap of the correlation matrix using Seaborn with annotations."
  • Example:
corr = df.select_dtypes(include='number').corr()
sns.heatmap(corr, annot=True, cmap='coolwarm', fmt='.2f')
plt.title('Correlation Heatmap')
plt.show()

Prompt 11: Time Series Line Plot

  • Task: Plot monthly sales trend with a rolling average of 3 months.
  • Prompt: "Convert date to datetime, set as index, resample by month, plot sales and rolling mean."
  • Example:
df['date'] = pd.to_datetime(df['date'])
df.set_index('date', inplace=True)
monthly = df['sales'].resample('M').sum()
monthly.plot(label='Monthly Sales')
monthly.rolling(window=3).mean().plot(label='3-Month Rolling Avg')
plt.legend()
plt.title('Monthly Sales Trend')
plt.show()

4. Expert Prompts: Performance and Automation

Prompt 12: Efficient Column Transformation with apply vs Vectorization

  • Task: Convert a column of strings to lowercase using vectorized operations instead of apply.
  • Prompt: "Use .str.lower() on name column to avoid slow apply."
  • Example:
# Slow
df['name_lower'] = df['name'].apply(lambda x: x.lower())
# Fast (vectorized)
df['name_lower'] = df['name'].str.lower()

Prompt 13: Chained Operations with pipe

  • Task: Apply a sequence of cleaning steps (drop nulls, filter, rename) using pipe.
  • Prompt: "Chain dropna, query, and rename using .pipe() for readability."
  • Example:
def drop_nulls(df):
    return df.dropna()

def filter_europe(df):
    return df[df['region'] == 'Europe']

def rename_cols(df):
    return df.rename(columns={'sales': 'revenue'})

cleaned = (df.pipe(drop_nulls)
             .pipe(filter_europe)
             .pipe(rename_cols))

Prompt 14: Parallel Processing with swifter

  • Task: Apply a slow function to a large DataFrame in parallel.
  • Prompt: "Use swifter.apply to parallelize a custom function on a DataFrame."
  • Example:
import swifter

def complex_calc(x):
    # some heavy computation
    return x ** 2 + 1

df['result'] = df['value'].swifter.apply(complex_calc)

Prompt 15: Automated Report Generation with Jinja2 and Matplotlib

  • Task: Generate an HTML report containing summary stats and plots from a DataFrame.
  • Prompt: "Create a function that renders a Jinja2 template with df.describe() and a saved plot."
  • Example:
from jinja2 import Template
import matplotlib.pyplot as plt

# Save plot
plt.figure()
df['age'].hist()
plt.savefig('age_hist.png')

# Render HTML
template = Template('''
<h2>Report</h2>
{{ table }}
<img src='age_hist.png'>
''')
html = template.render(table=df.describe().to_html())
with open('report.html', 'w') as f:
    f.write(html)

Conclusion

Prompts are not magic; they are structured thinking. By breaking down a data science task into clear steps—load, inspect, transform, visualize, and automate—you reduce cognitive load and improve reproducibility. The 15 prompts in this collection cover the most common operations in Pandas, Matplotlib, and Seaborn. Start by copying them directly, then modify the parameters to fit your data. Over time, you will internalize these patterns and develop your own library of prompts. The best data scientists are not those who know every function, but those who can quickly translate a business question into a sequence of precise operations. Use these prompts as a foundation, and you will spend less time debugging and more time discovering insights.

Further Reading

← All posts

Comments