You've heard that LLMs can write code, but can they actually do data science? Not just generate a scatter plot, but think through a messy business problem, design an experiment, catch data leakage, and explain the trade-offs? The answer is yes — if you know how to prompt. This playbook is a collection of 12 battle-tested prompts for data scientists, each one designed to solve a specific, real-world task. Whether you're cleaning data, building a model, or trying to explain your results to a non-technical stakeholder, these prompts will save you hours and improve the quality of your work. Let's dive in.
1. The Data Audit: Understanding What You're Working With
Purpose: Before any analysis, you need to understand the structure, quality, and quirks of your dataset. This prompt turns the AI into a data auditor that inspects your data and flags potential issues.
Prompt:
Act as a senior data scientist. I'm going to provide you with a dataset (CSV or JSON). Perform a thorough data audit and return a structured report covering:
- Data types and missing values per column
- Descriptive statistics (mean, median, std, percentiles) for numerical columns
- Cardinality and top values for categorical columns
- Potential data quality issues (outliers, impossible values, duplicates)
- Suggestions for cleaning and feature engineering
Here's the data: [paste a sample or describe the schema]
Example: You're analyzing customer churn data. The AI might flag that the tenure column has negative values, or that the payment_method column has 5 different spellings of "credit card". This gives you a head start on cleaning.
2. Hypothesis Generation: From Data to Questions
Purpose: Data science isn't just about running models; it's about asking the right questions. This prompt helps you brainstorm potential hypotheses and relationships in your data before you start testing.
Prompt:
I have a dataset with features: [list features]. Based on this domain (e.g., e-commerce, healthcare, finance), generate a list of 10-15 hypotheses about how these features might influence the target variable [target]. For each hypothesis, explain the reasoning and suggest how to test it (e.g., correlation analysis, A/B test, regression).
Example: For a retail dataset with features like time_on_site, pages_viewed, and purchase_amount, the AI might hypothesize that time_on_site has a non-linear relationship with purchase likelihood, and suggest checking for a threshold effect.
3. Data Cleaning: Automating the Grunt Work
Purpose: Cleaning data is often 80% of a data scientist's job. This prompt helps you write robust data cleaning code for common issues like missing values, outliers, and inconsistent formats.
Prompt:
Write Python code using pandas to clean the following dataset. The code should:
- Impute missing values (use median for numerical, mode for categorical)
- Remove or cap outliers using IQR or Z-score
- Standardize string formats (lowercase, strip whitespace, fix typos)
- Handle duplicate rows
- Convert date columns to datetime
Here's the data sample: [paste sample]
Example: The AI might generate a function that uses df['age'].fillna(df['age'].median()) for missing ages, and a lambda to standardize names. This is code you can immediately adapt and run.
4. Feature Engineering: Creating Predictive Power
Purpose: Features make or break a model. This prompt helps you brainstorm and implement new features from existing data, using domain knowledge and statistical techniques.
Prompt:
Given the following dataset with features: [list features], suggest 10 new features that could improve model performance for predicting [target]. For each feature, explain the rationale and provide Python code to create it using pandas/numpy. Prioritize features that capture non-linear relationships or interactions.
Example: For a house price dataset, the AI might suggest age_of_house (current year - year_built), price_per_sqft, and a has_garage flag. It would then show you how to compute these with pandas.
5. Building a Baseline Model: Start Simple
Purpose: Every data science project needs a baseline. This prompt helps you quickly build a simple model (e.g., logistic regression) and evaluate it, so you have a reference point for more complex models.
Prompt:
Using scikit-learn, build a baseline model for a classification/regression task. The data is in a CSV file at [path]. Use a train/test split (80/20) with stratified sampling. For classification, use logistic regression; for regression, use linear regression. Evaluate with appropriate metrics (accuracy, precision, recall, F1 for classification; RMSE, MAE for regression). Print a classification report or regression metrics. Return the code and the results.
Example: This prompt produces a complete script that loads the data, trains a model, and prints metrics. You can run it, see the baseline, and then decide if you need more complex models.
6. Hyperparameter Tuning: Getting the Best Performance
Purpose: Once you have a baseline, you need to optimize your model. This prompt guides the AI to perform hyperparameter tuning using techniques like GridSearchCV or RandomizedSearchCV.
Prompt:
Write Python code to perform hyperparameter tuning for a [model type] using scikit-learn. The data is at [path]. Use RandomizedSearchCV with 5-fold cross-validation to search over the following parameter grid: [list parameters]. Use accuracy/RMSE as the scoring metric. After finding the best parameters, train the final model and evaluate it on the test set. Print the best parameters and final metrics.
Example: For a Random Forest, the AI might generate a parameter grid like {'n_estimators': [100, 200], 'max_depth': [10, 20], 'min_samples_split': [2, 5]} and run the search, giving you the optimal settings.
7. Model Interpretation: Understanding Predictions
Purpose: You need to explain why your model makes certain predictions, especially for stakeholders. This prompt helps you generate SHAP or LIME analysis to interpret your model's decisions.
Prompt:
I have a trained machine learning model (sklearn pipeline) saved as [file]. Write Python code to interpret the model's predictions using SHAP. Load the model, compute SHAP values on a test set, and generate:
- A summary plot (beeswarm)
- A bar plot of mean absolute SHAP values
- A waterfall plot for a specific prediction
Explain how to interpret each plot and what to look for.
Example: The AI might produce code that uses shap.TreeExplainer for a Random Forest, and then visualize the top features driving churn predictions. This is invaluable for communicating with non-technical stakeholders.
8. Visualizing Results: Telling the Data Story
Purpose: Effective visualization is key to conveying insights. This prompt helps you create publication-ready charts with matplotlib or seaborn, including proper labeling and styling.
Prompt:
Create a set of data visualizations using Python (matplotlib/seaborn) for the dataset at [path]. Generate:
- A histogram of [column] with a KDE overlay
- A boxplot of [column] by [categorical column]
- A correlation heatmap of numerical features
- A pairplot of the top 5 features by correlation with target
Customize the plots with titles, axis labels, and a consistent color scheme. Save each plot to [folder] as PNG with 150 DPI.
Example: The AI might generate a set of plots that reveal the distribution of customer ages, the relationship between income and spending, and which features are most correlated. These plots can go straight into a report.
9. A/B Testing: Designing Experiments
Purpose: When you need to test a new feature or model in production, you need a proper experiment design. This prompt helps you plan an A/B test, including sample size calculation and analysis.
Prompt:
Design an A/B test to compare [control] vs [treatment]. Assume a baseline conversion rate of [rate] and a minimum detectable effect of [MDE]. Calculate the required sample size for 95% confidence and 80% power. Provide Python code to perform the calculation (using statsmodels or scipy) and to analyze the results (using a t-test or chi-squared test). Include a discussion of potential pitfalls (e.g., peeking, Simpson's paradox).
Example: For a new checkout flow, the AI might calculate that you need 10,000 users per group, and provide code to run a two-proportion z-test on the results.
10. Automating Reports: The Data Science Pipeline
Purpose: Automating repetitive reporting tasks saves time. This prompt helps you create a Python script that generates an automated report (e.g., with Jupyter, Papermill, or a simple HTML template).
Prompt:
Write a Python script that generates an automated data report. The script should:
- Read data from [source]
- Compute key metrics (e.g., revenue, active users, churn)
- Create visualizations (e.g., time series, bar charts)
- Output an HTML report with the metrics and charts embedded
Use the `yaml` package for configuration and `jinja2` for templating. Provide the full code and a sample configuration file.
Example: The AI might produce a script that reads a sales CSV, calculates daily revenue, and generates an HTML report with a chart, saving it to report.html. You can schedule this with cron to run daily.
11. Communicating Results: From Code to Story
Purpose: Data scientists must communicate findings to non-technical audiences. This prompt helps you translate technical results into a clear, non-technical summary.
Prompt:
I have the following results from a data analysis: [paste results]. Write a summary for a non-technical stakeholder. Include:
- The key findings (in plain language)
- The business implication (what does this mean for our business?)
- Recommended actions
- Any caveats or limitations
Keep it under 300 words and avoid jargon.
Example: If your model shows that churn is highest among customers who haven't logged in for 30 days, the AI might suggest an email campaign to re-engage them. This is the final step in turning data into action.
12. Debugging and Optimizing: When Things Go Wrong
Purpose: Even the best data scientists hit errors or slow code. This prompt helps you debug errors and optimize performance.
Prompt:
I'm getting the following error in my data science code: [paste error]. Explain what causes this error and how to fix it. Additionally, my current code is slow on a large dataset. Profile the code (using cProfile or line_profiler) and suggest optimizations (e.g., vectorization, using categoricals, reducing memory).
Example: If you get a MemoryError when loading a large CSV, the AI might suggest reading in chunks with pd.read_csv(..., chunksize=10000) and using dtype to optimize memory.
Final Thoughts
These 12 prompts are just the beginning. The key to successful prompt engineering in data science is to think of the LLM as a collaborative colleague: give it context, specify the output format, and iterate. The prompts above are designed to be modular — you can combine them or adapt them to your specific problem. As you use them, you'll develop your own style and discover new ways to leverage AI in your workflow. The goal is not to replace your judgment, but to automate the mundane and amplify your expertise. So next time you're stuck on a data task, try one of these prompts — you might be surprised at how much time you save. Happy data sleuthing!
Comments