From Messy CSVs to ML Models: 15 Data Science Prompts for Cleaner Data, Sharper Insights, and Better Visuals

Introduction

You've spent hours cleaning a CSV, only to realize the date column is a mix of formats and your model refuses to train. We've all been there. Data science is 80% data wrangling and 20% actual modeling, but most tutorials skip the boring parts. This guide is your cheat sheet — 15 battle-tested prompts that turn an AI assistant into your personal data analyst. From pandas one-liners to full EDA reports and interactive dashboards, these prompts will save you time, reduce errors, and help you communicate insights like a pro. No fluff, just copy-paste prompts with real examples.

Section 1: Data Cleaning and Preparation

1.1 The Data Audit Prompt

What it does: Scans your dataset for common issues like missing values, duplicates, inconsistent datatypes, and outliers. Perfect for a quick health check before any analysis.

The prompt:

Act as a senior data analyst. I have a DataFrame loaded as `df`. Perform a thorough data audit and return a structured report with the following sections: (1) Shape and column list with datatypes, (2) Missing values per column (count and percentage), (3) Duplicate rows count, (4) For each numeric column: min, max, mean, median, standard deviation, and a list of potential outliers (values beyond 3 standard deviations from the mean), (5) For each categorical column: number of unique values and top 5 most frequent values. Use pandas built-in methods only. Provide the output as a Markdown table for each section. If any column has more than 50% missing values, flag it as 'drop candidate'.

Example usage: You've just loaded a customer dataset from a CRM export. Run this prompt in a Jupyter notebook with the df already defined. The AI will produce a clear report highlighting that 'last_purchase_date' has 30% missing values and 'age' has a few negative entries — exactly what you need to plan your cleaning steps.

1.2 The Universal Type Fixer

What it does: Automatically converts messy columns to proper datatypes: dates, numbers, and booleans. Handles European number formats (commas as decimal separators) and mixed date formats.

The prompt:

Write a Python function `fix_datatypes(df)` that iterates over each column and attempts to infer and convert the datatype. For each column: (1) If the column name contains 'date' or 'time', try to parse it with `pd.to_datetime` using a list of common date formats (e.g., '%Y-%m-%d', '%d/%m/%Y', '%m/%d/%Y', '%Y%m%d'). (2) If the column contains numeric values that are stored as strings, remove any currency symbols and thousand separators, and convert to float. (3) If the column has only 'True'/'False', 'Yes'/'No', or 0/1 values, convert to boolean. (4) Return the converted DataFrame and a log of changes made. Use `pd.to_datetime`, `pd.to_numeric`, and `pd.api.types.is_numeric_dtype` where appropriate. Handle exceptions gracefully and log warnings instead of crashing.

Example usage: Your sales data has a 'price' column with values like "€1.234,56" and a 'date' column with mixed formats. This function will normalize everything, saving you from manual regex hell.

1.3 The Outlier Capper

What it does: Caps outliers using the IQR method, preventing extreme values from skewing your models. Especially useful for linear models and clustering.

The prompt:

Write a function `cap_outliers(df, columns=None, multiplier=1.5)` that takes a DataFrame and an optional list of column names. For each numeric column (or the specified ones), calculate the IQR (Q3-Q1) and cap values below Q1 - multiplier*IQR to that lower bound, and values above Q3 + multiplier*IQR to the upper bound. Return a new DataFrame with capped values and a dictionary showing how many values were capped per column. Use `df.quantile` and `numpy.where`. If a column is not numeric, skip it with a warning.

Example usage: Your ML model for house prices is heavily influenced by a few mansions. Cap the 'price' column at 1.5*IQR to reduce their impact — the model will generalize better.

Section 2: Exploratory Data Analysis (EDA)

2.1 The One-Stop EDA Report Generator

What it does: Generates a comprehensive EDA report for a DataFrame, including summary statistics, correlation matrix, missing value heatmap, and distribution plots — all in one go.

The prompt:

Act as a data scientist. Generate a complete EDA report for the DataFrame `df`. Use `matplotlib` and `seaborn` for visualizations. The report should include: (1) A summary table of descriptive statistics for all numeric columns (count, mean, std, min, quartiles, max). (2) A heatmap of the correlation matrix (use `sns.heatmap`). (3) Histograms for each numeric column (use `df.hist` with `figsize` and `bins`). (4) Box plots for each numeric column to identify outliers. (5) Bar charts for each categorical column showing value counts. (6) A count of missing values per column in a bar plot. Write the code as a single script that outputs all plots in a grid layout. Use `plt.tight_layout()` and `plt.show()`. Include comments explaining each section. If a column has many unique values, limit the bar chart to the top 10.

Example usage: You're exploring a new dataset and need a quick overview. Run this prompt in a Jupyter notebook, and you'll get a full picture of distributions, correlations, and missing data in seconds.

2.2 The Correlation Whisperer

What it does: Identifies the most influential features for a target variable using correlation and mutual information, helping you select features for modeling.

The prompt:

Write a Python script that calculates the correlation between each feature and a target column `'target'` in DataFrame `df`. Use both Pearson correlation (for linear relationships) and Spearman rank correlation (for monotonic relationships). Additionally, compute mutual information for all features using `sklearn.feature_selection.mutual_info_classif` if the target is categorical, or `mutual_info_regression` if numeric. Output a table ranking features by absolute correlation and mutual information, and print the top 5 features for each metric. Handle missing values by dropping rows with NaN in the target. Use `scipy.stats.pearsonr` and `spearmanr`. Provide the code with comments.

Example usage: You're building a churn prediction model. This prompt reveals that 'tenure' and 'monthly_charges' are the top predictors, so you can focus your modeling effort on them.

2.3 The Missing Data Strategist

What it does: Analyzes missing data patterns and recommends the best imputation strategy for each column.

The prompt:

Act as a data scientist. For DataFrame `df`, analyze the missing data patterns. Use `missingno` library to visualize the nullity matrix and correlation if available (if not, use `df.isnull()`). For each column with missing values, determine if the missingness is MCAR, MAR, or MNAR based on correlations with other columns (e.g., if missingness in column A correlates with values in column B, it's MAR). Then, for each column, recommend an imputation method: mean/median for numeric, mode for categorical, forward-fill or backward-fill for time series, or model-based imputation (e.g., KNNImputer) if the column is important. Output a report with a table and a short explanation for each column. Provide code that performs the imputation using `sklearn.impute.SimpleImputer` and `KNNImputer`.

Example usage: Your survey data has missing income values that correlate with education level. The prompt suggests using KNNImputer with 'education' as a feature, which is far better than dropping rows.

Section 3: Machine Learning Modeling

3.1 The Auto-Preprocessor Builder

What it does: Creates a scikit-learn Pipeline that preprocesses numeric and categorical features, handles missing values, and applies scaling — ready for any model.

The prompt:

Write a Python function `build_preprocessor(numeric_features, categorical_features)` that returns a `ColumnTransformer` with: (1) For numeric features: `SimpleImputer(strategy='median')` followed by `StandardScaler()`. (2) For categorical features: `SimpleImputer(strategy='most_frequent')` followed by `OneHotEncoder(handle_unknown='ignore')`. Use `sklearn.compose.ColumnTransformer` and `sklearn.pipeline.Pipeline`. The function should accept lists of feature names. Also write a second function `build_model_pipeline(model, preprocessor)` that combines the preprocessor with a given model (e.g., `RandomForestClassifier`) into a single Pipeline. Provide usage example with `make_classification` data.

Example usage: You're doing a Kaggle competition. This pipeline saves you from manually encoding and scaling every time you try a new model.

3.2 The Model Comparison Harness

What it does: Trains and evaluates multiple classification models with cross-validation, producing a comparison table of metrics.

The prompt:

Write a script that loads a dataset (e.g., from `sklearn.datasets.load_breast_cancer`), splits it into train/test sets (80/20), and trains the following classifiers: Logistic Regression, Random Forest, Gradient Boosting, and SVM. Use `sklearn.model_selection.cross_val_score` with 5-fold CV to compute accuracy, precision, recall, and F1-score for each model. Also compute ROC-AUC. Output a pandas DataFrame with models as rows and mean metrics as columns, sorted by ROC-AUC. Include the code and a printout of the table. Use `random_state=42` for reproducibility.

Example usage: You want to quickly see which algorithm works best for your dataset. This script gives you a clear leaderboard in under a minute.

3.3 The Hyperparameter Tuner

What it does: Performs randomized search for hyperparameter tuning, with clear output of best parameters and score.

The prompt:

Write a Python script that uses `sklearn.model_selection.RandomizedSearchCV` to tune a `RandomForestClassifier` on a dataset `X_train`, `y_train`. Define a parameter grid with at least 5 hyperparameters (e.g., `n_estimators`, `max_depth`, `min_samples_split`, `min_samples_leaf`, `max_features`). Use 5-fold cross-validation and `scoring='f1'` (or 'roc_auc' for binary). Print the best parameters and the best cross-validation score. Also fit the best estimator on the full training set and evaluate on `X_test`, `y_test`, printing accuracy, precision, recall, F1, and confusion matrix. Use `n_iter=20` and `random_state=42`.

Example usage: Your Random Forest baseline is decent, but you know it can be better. This prompt finds the optimal hyperparameters without you manually guessing.

Section 4: Interpretation and Reporting

4.1 The Feature Importance Explainer

What it does: Uses SHAP to explain model predictions and creates a summary plot of feature importance.

The prompt:

Act as an ML interpretability expert. For a trained model `model` and a dataset `X_test`, compute SHAP values using the `shap` library. If the model is a tree-based model, use `shap.TreeExplainer`; if it's a linear model, use `shap.LinearExplainer`. Create a summary plot (`shap.summary_plot`) and a bar plot of mean absolute SHAP values (`shap.summary_plot` with `plot_type='bar'`). Provide code that prints the top 10 features by importance and explains what each of the top 3 features means in plain language. Handle cases where SHAP is slow by sampling 100 rows. Use `matplotlib` to display plots.

Example usage: Your manager asks why the model rejected a loan application. SHAP values show that 'credit_score' and 'debt_to_income' are driving the decision, making it easy to explain.

4.2 The Model Report Writer

What it does: Generates a human-readable Markdown report of model performance, including metrics, confusion matrix, and key findings.

The prompt:

Write a Python function `generate_model_report(model, X_test, y_test, model_name='Model')` that: (1) Computes accuracy, precision, recall, F1-score, and confusion matrix using `sklearn.metrics`. (2) Generates a Markdown report with the model name, the metrics in a table, a text description of the confusion matrix (e.g., 'The model correctly predicted 95% of positive cases'), and a section 'Key Insights' that includes the most important features from the model (if available via `feature_importances_` or coefficients). The function should return the Markdown string. Use `sklearn.metrics.classification_report` and `confusion_matrix`. Format numbers to 2 decimals.

Example usage: You need to document your model for a project report. This function produces a clean Markdown section you can paste directly into your analysis.

4.3 The A/B Test Analyzer

What it does: Performs a statistical analysis of A/B test results, including hypothesis testing and confidence intervals.

The prompt:

Act as a statistician. I have two groups: control and treatment, with counts of conversions and total users. Write a Python script that: (1) Calculates conversion rates for both groups. (2) Performs a two-proportion z-test using `statsmodels.stats.proportion.proportions_ztest`. (3) Calculates the 95% confidence interval for the difference in proportions using `statsmodels.stats.proportion.confint_proportions_2indep`. (4) Interprets the p-value: if p < 0.05, conclude that the treatment has a statistically significant effect. Print a summary table with group, conversions, total users, conversion rate, and CI. Include the code and comments.

Example usage: Your marketing team ran a new landing page. This script tells you if the 2% lift is real or just noise.

Section 5: Visualization and Dashboards

5.1 The Storytelling Visualizer

What it does: Creates a multi-panel matplotlib figure that tells a story about a DataFrame, with titles, labels, and annotations.

The prompt:

Generate a Python script that creates a 2x2 matplotlib figure for a DataFrame `df` with columns 'date', 'revenue', 'customers', and 'region'. The four plots should be: (1) Line plot of revenue over time, (2) Bar chart of average revenue by region, (3) Histogram of customers per day, (4) Scatter plot of revenue vs customers, colored by region. Add a main title that summarizes the business insight (e.g., 'Revenue growth driven by East region'). Use `plt.subplots`, `set_title`, `set_xlabel`, `set_ylabel`. Include a tight layout and save the figure to 'eda_plots.png'. Write the code with comments.

Example usage: You need a visual summary for a stakeholder meeting. This prompt generates a figure that immediately shows the key trends.

5.2 The Interactive Dashboard Builder

What it does: Creates an interactive Plotly dashboard with dropdowns, sliders, and hover tooltips.

The prompt:

Build an interactive dashboard using Plotly Express and Dash. Load a DataFrame `df` with columns 'date', 'product', 'sales', 'region'. Create a bar chart that shows total sales by product, with a dropdown filter for region. Add a line chart of sales over time, with a slider to select date ranges. Use `dcc.Dropdown` and `dcc.RangeSlider`. The layout should have a title, the dropdown, the range slider, and the two graphs stacked vertically. Use `app.callback` to update the graphs based on user input. Provide the complete code for a Dash app that runs on localhost:8050. Include `if __name__ == '__main__': app.run_server(debug=True)`.

Example usage: You want to share an interactive sales dashboard with your team. This prompt gives you a working Dash app you can customize.

5.3 The Chart Type Recommender

What it does: Recommends the best chart type for a given dataset and columns, based on data characteristics.

The prompt:

Act as a data visualization expert. For a DataFrame `df`, write a function `recommend_chart(df, x_col, y_col=None)` that analyzes the columns and returns a recommendation for the best chart type. Consider: (1) If y_col is None, recommend a bar chart if x_col is categorical, or a histogram if x_col is numeric. (2) If y_col is provided, and both are numeric, recommend a scatter plot (add a trend line). If one is categorical and the other numeric, recommend a box plot or bar chart. If both are categorical, recommend a stacked bar chart or heatmap of counts. Use `seaborn` to create the recommended chart as a function that also plots it. Output the recommendation and the code to generate the plot.

Example usage: You're unsure how to visualize the relationship between 'age' and 'income'. This prompt suggests a scatter plot with a trend line and generates it for you.

Conclusion

These 15 prompts cover the entire data science workflow — from cleaning messy data to building and explaining models, and finally creating compelling visuals. The key is to adapt them to your specific dataset and context. Start with the data audit, then move to EDA, modeling, and reporting. As you use them, you'll find your own variations. Bookmark this page, and next time you're stuck on a data task, let these prompts be your guide. And remember: the best prompt is the one that saves you time without sacrificing accuracy. Now go explore your data.

← All posts

Comments