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

Why You Need Structured Prompts for Data Science

Data science workflows often involve repetitive tasks—cleaning messy datasets, generating exploratory plots, or computing grouped statistics. Without a systematic approach, you waste hours rewriting code. This article provides 10 battle-tested prompts designed for Pandas, Matplotlib, and Seaborn users. Each prompt includes a real-world scenario, a ready-to-use instruction, and an example output. Whether you're a junior analyst or a seasoned ML engineer, these prompts will accelerate your analysis pipeline.

1. Automated Data Cleaning Report

Task: Generate a comprehensive summary of missing values, data types, and outliers.

Prompt: "Using the Pandas library on the DataFrame df, produce a report that lists for each column: data type, count of non-null values, percentage of missing values, number of unique values, and a flag indicating whether outliers exist (based on the IQR rule). Output the results as a formatted Markdown table."

Example Result: For a customer churn dataset, the prompt returns:

Column Dtype Non-Null Missing % Unique Outliers
tenure int64 7043 0.0% 76 Yes
MonthlyCharges float64 7043 0.0% 1585 No

This helps you prioritize cleaning steps—for instance, deciding whether to impute or drop columns.

2. Grouped Aggregation with Custom Metrics

Task: Compute multiple statistics per group without repetitive code.

Prompt: "For the DataFrame sales, group by the 'region' column. For each group, compute: total revenue, average order value, standard deviation of revenue, and the count of transactions. Output the result as a DataFrame sorted by total revenue descending."

Example Result:

sales.groupby('region').agg({
    'revenue': ['sum', 'mean', 'std'],
    'order_id': 'count'
}).sort_values(('revenue', 'sum'), ascending=False)

You get a clear view of which regions perform best and how volatile their revenue is.

3. Correlation Heatmap with Annotations

Task: Quickly identify relationships between numeric features.

Prompt: "Using Seaborn, create a heatmap of the correlation matrix for all numeric columns in df. Annotate each cell with the correlation coefficient rounded to two decimals, use a diverging colormap, and set the figure size to 10x8. Rotate the x-axis labels by 45 degrees for readability."

Example Result: A visually rich heatmap where strong positive correlations appear in dark red and negative ones in blue. This is invaluable for feature selection before modeling.

4. Time Series Resampling and Trend Detection

Task: Convert daily data to monthly averages and detect trends.

Prompt: "Resample the time series DataFrame df_ts (with a daily date index) to monthly frequency using the mean. Then fit a linear regression line using NumPy to the resampled values and plot both the monthly averages and the trend line using Matplotlib. Add a title and grid."

Example Result: A clean plot showing seasonal patterns and an overall upward or downward trend. This helps in forecasting and anomaly detection.

5. Outlier Detection and Flagging

Task: Mark rows that contain extreme values.

Prompt: "For each numeric column in df, calculate the lower and upper bounds as Q1 - 1.5IQR and Q3 + 1.5IQR. Create a new boolean column 'is_outlier' that is True if any numeric value in that row falls outside its column's bounds. Return the count of outlier rows and a sample of 5 such rows."

Example Result: Identifies 23 rows with extreme values in a 1000-row dataset—useful for data quality audits.

6. Distribution Comparison via Subplots

Task: Compare histograms of a feature across multiple categories.

Prompt: "Using Matplotlib, create a 2x2 grid of subplots. In each subplot, plot a histogram of the 'price' column for a different category of 'product_type'. Use consistent bins and x-axis limits across all subplots. Add a title to each subplot indicating the category."

Example Result: Four histograms side-by-side showing that electronics have a bimodal price distribution while clothing is left-skewed. This uncovers market segment differences.

7. Pivot Table with Marginal Totals

Task: Create a cross-tabulation with row and column totals.

Prompt: "Generate a Pandas pivot table from df using 'year' as index, 'region' as columns, and 'revenue' as values (aggregated by sum). Add margins=True to include row and column totals. Display the result."

Example Result: A compact table showing revenue by year and region, plus grand totals—perfect for executive summaries.

8. Pair Plot with Color-Coded Groups

Task: Visualize pairwise relationships across many features.

Prompt: "Using Seaborn's pairplot, plot all numeric columns in df against each other. Color the points by the 'churn' categorical column. Set the diagonal to show KDE plots instead of histograms. Adjust the palette to 'Set2'."

Example Result: A multi-plot grid where you instantly see that churned customers have lower tenure and higher monthly charges. This drives hypothesis generation.

9. Missing Data Imputation Strategy

Task: Automatically choose and apply imputation per column type.

Prompt: "For each column in df that has missing values, impute as follows: if numeric, fill with the median; if categorical, fill with the mode. Print the number of missing values before and after imputation for each column. Use Pandas fillna with inplace=False."

Example Result: A log showing that "income" had 45 missing values (filled with median) and "education" had 12 (filled with mode). This ensures your model doesn't break on nulls.

10. Export Cleaned Dataset with Metadata

Task: Save a processed DataFrame along with a human-readable summary.

Prompt: "After cleaning df, export the cleaned DataFrame to a CSV file named 'cleaned_data.csv'. Also generate a text file 'metadata.txt' that lists: number of rows and columns, list of column names with their dtypes, and the date of export. Use Python's datetime module."

Example Result: You get both a ready-to-analyze CSV and a metadata file that documents the data lineage—critical for reproducibility.

Conclusion

These 10 prompts cover the essential data science tasks: cleaning, aggregation, visualization, and export. By embedding them into your daily workflow, you reduce coding errors and speed up exploration. Start by copying the prompts into your Jupyter Notebook or Python script, then adapt them to your specific datasets. For deeper learning, refer to the official Pandas documentation (pandas.pydata.org) and Seaborn examples (seaborn.pydata.org). Now go turn raw data into actionable insights.

← All posts

Comments