Data science isn't just about writing code—it's about asking the right questions. Every project, from cleaning messy datasets to tuning a neural network, begins with a query. But what if you could ask an LLM to handle the heavy lifting? This guide offers 12 battle-tested prompts that transform LLMs into your data science teammate. Whether you're a beginner wrestling with pandas or a veteran optimizing ML pipelines, these prompts will save you hours. Let's dive in.
1. The Data Audit: Know Your Mess Before You Clean It
Prompt: "Act as a data quality auditor. I'm about to work with a dataset that has the following columns and sample rows: [paste schema and 5 rows]. Identify potential issues: missing values, inconsistent formats, outliers, duplicates, and data type mismatches. For each issue, suggest a specific remediation strategy using Python/pandas. Output as a markdown table."
Why it works: This prompt forces the LLM to think systematically about data quality, a crucial first step. It also gives you a clear action plan.
Example: You're analyzing customer data with columns like age, income, and signup_date. The prompt will flag that age has negative values, income has currency symbols, and signup_date mixes formats. It'll then recommend code to fix each.
2. The Automated Cleaner: Generate a Reproducible Cleaning Script
Prompt: "Generate a Python function clean_data(df) that performs the following operations: removes duplicates, imputes missing values for numeric columns using median (and for categorical using mode), caps outliers at the 1st and 99th percentile, and standardizes column names to snake_case. Include docstring and type hints. Assume pandas is imported."
Why it works: This prompt produces a reusable, production-ready function, not just ad-hoc code. It enforces best practices like type hints and documentation.
Example: The output would be a function you can drop into any project, saving you from writing boilerplate cleaning code every time.
3. The EDA Companion: Uncover Hidden Patterns
Prompt: "I'm performing exploratory data analysis on a dataset with columns [list]. Write a series of Python commands (using pandas, matplotlib, seaborn) to: 1) compute descriptive statistics, 2) visualize distributions for numeric columns, 3) plot correlation heatmap, 4) show count plots for categorical columns. Also, generate a text summary of what to look for in these outputs."
Why it works: EDA is about both visualization and interpretation. This prompt gives you both the code and the analytical lens.
Example: For a housing dataset, it might suggest plotting price distribution, checking skewness, and recommending a log transform if needed.
4. The Feature Engineer: Create Meaningful Features from Raw Data
Prompt: "Given a dataset with columns [list], propose 10 new features that could improve predictive performance for a [regression/classification] task. For each feature, explain the rationale and provide the pandas code to create it. Prioritize features that capture interactions, temporal patterns, or domain-specific knowledge."
Why it works: Feature engineering is where domain expertise meets creativity. This prompt leverages the LLM's knowledge to suggest features you might not have considered.
Example: For a churn prediction task, it might suggest features like tenure_in_months, avg_transaction_amount, and days_since_last_login, each with code.
5. The Model Selector: Choosing the Right Algorithm
Prompt: "I have a dataset with [number] rows and [number] features. The target is [binary/multi-class/continuous]. I need a model that is [interpretable/fast/accurate]. Compare 5 appropriate algorithms, including pros/cons, typical use cases, and hyperparameters to tune. Recommend one and justify."
Why it works: This prompt turns the LLM into a model selection advisor, helping you avoid common pitfalls like using a black-box model when interpretability is key.
Example: For a small dataset with binary classification and need for interpretability, it might recommend logistic regression or a decision tree, and explain why XGBoost might overfit.
6. The Hyperparameter Tuner: Get the Best Performance
Prompt: "Write Python code using scikit-learn's GridSearchCV to tune hyperparameters for a [RandomForest/SVM/XGBoost] model. The parameter grid should include [list of parameters] with sensible ranges. Use a pipeline that includes scaling (if needed) and evaluate with cross-validation. Print the best parameters and score."
Why it works: Hyperparameter tuning can be tedious. This prompt gives you a ready-to-run script that follows best practices, including pipelines to prevent data leakage.
Example: For RandomForest, it might suggest grids for n_estimators, max_depth, and min_samples_split, and the code to run the search.
7. The Code Translator: From R to Python (or Vice Versa)
Prompt: "Translate the following R code to Python using pandas and scikit-learn. Ensure the logic is preserved and idiomatic Python is used. Here's the code: [paste R code]."
Why it works: Data scientists often switch between languages. This prompt saves time and helps you learn by comparing implementations.
Example: Translating a dplyr chain to pandas operations, or glm to LogisticRegression.
8. The Debugger: Fix That Pesky Error
Prompt: "I'm getting the following error when running this code: [paste error traceback and code]. Explain the cause and provide a corrected version. Also, suggest how to prevent this error in the future."
Why it works: Debugging is a daily task. This prompt provides a clear explanation and a fix, turning an error into a learning opportunity.
Example: If you get a ValueError about mismatched shapes, the LLM will explain the issue and show you how to reshape or align data correctly.
9. The Visualization Pro: Create Publication-Ready Charts
Prompt: "Create a Python script using matplotlib and seaborn to generate a [histogram/scatter plot/box plot] for data in a pandas DataFrame. The plot should have a title, axis labels, and a grid. Use a modern style and a color palette that is colorblind-friendly. Save the figure as a high-resolution PNG."
Why it works: Good visualization is crucial for communication. This prompt ensures your charts are polished and accessible.
Example: For a scatter plot of price vs. area, it might use seaborn's scatterplot with a regression line and custom colors.
10. The Model Explainer: Interpret Your Black Box
Prompt: "I have a trained [XGBoost/neural network] model. Using SHAP, generate code to: 1) compute SHAP values for a test set, 2) create a summary plot, and 3) explain the top 5 features for a single prediction. Provide a brief interpretation of the output."
Why it works: Model interpretability is increasingly important for compliance and trust. This prompt gives you practical SHAP code and explains how to read it.
Example: The output might show that income is the most important predictor for a credit risk model, and for a specific prediction, it might explain why a high income increased the predicted score.
11. The Deployment Helper: From Notebook to Production
Prompt: "I have a trained scikit-learn model. Write a FastAPI application that serves predictions via a POST endpoint /predict. The app should load the model from a file, accept JSON input, and return a prediction. Include input validation and error handling."
Why it works: Deploying models is a common pain point. This prompt gives you a production-ready API skeleton, making your model accessible to other services.
Example: The generated code would include a pydantic model for input, a function to load the model, and a route that returns predictions.
12. The Data Science Mentor: Get Guidance and Best Practices
Prompt: "I'm working on a [type of project] and I'm stuck at [specific step]. Can you explain the best practices for this step, common mistakes to avoid, and provide a small example? Focus on [specific aspect]."
Why it works: Sometimes you need expert advice, not code. This prompt turns the LLM into a mentor who can guide you through the process.
Example: If you're stuck on handling imbalanced data, it might explain options like resampling, class weights, and synthetic data generation, with a small example.
Wrapping Up
These 12 prompts are your toolkit for a smoother data science workflow. They don't replace your expertise—they amplify it, handling the mundane and complex tasks so you can focus on the bigger picture. The key is to be specific in your prompts: the more context you give, the better the output. Start with one prompt that addresses your current pain point, and adapt it to your needs. As LLMs evolve, so will their capabilities, but the art of prompting will remain a valuable skill in your data science arsenal. So go ahead, paste a prompt into your favorite LLM, and watch your productivity soar.
If you found these prompts helpful, check out more articles on ASI Biont's blog for insights into AI tools, automation, and data science. And remember: the best prompt is the one you actually use.
Comments