From Messy CSVs to Deployed Models: 30 Battle-Tested AI Prompts for the Entire Data Science Pipeline

Every data scientist knows the feeling: you've got a raw dataset, a deadline, and a blank notebook. The first few hours are always the same — wrestling with missing values, figuring out what the columns actually mean, and writing the same boilerplate code you've written a hundred times. What if you could skip straight to the interesting part? That's where LLM-based prompt engineering comes in. With the right prompts, you can turn a large language model into a senior colleague who writes code, explains concepts, and suggests next steps — all without leaving your IDE.

This guide is a curated collection of 30 prompts organized by the natural stages of a data science project, from initial data exploration to model deployment. Each prompt includes a practical example and a brief explanation of when to use it. Whether you're a beginner looking for a coding buddy or an experienced practitioner who wants to automate the boring stuff, these prompts will help you work faster and smarter. Let's dive in.

1. Data Exploration and Cleaning

1.1 Initial Data Overview

Task: Get a quick summary of a dataset's structure and quality.

Prompt:
"You are a data scientist. I have a pandas DataFrame loaded from 'customer_data.csv'. Give me a concise summary including: shape, column names, data types, number of missing values per column, and basic statistics for numerical columns. Use pandas code to generate this summary, and then interpret the output."

Example Result:

import pandas as pd

df = pd.read_csv('customer_data.csv')
print(df.shape)
print(df.dtypes)
print(df.isnull().sum())
print(df.describe())

The model then outputs a text explanation: 'The dataset has 10,000 rows and 15 columns. Three columns have missing values: 'age' (5%), 'income' (10%), and 'churn' (2%). The average age is 45.2 years...'

When to Use: This is your first step with any new dataset. It helps you quickly assess data quality and plan your cleaning strategy.

1.2 Handling Missing Values

Task: Generate code to impute missing values appropriately.

Prompt:
"I have a DataFrame with missing values in columns 'age', 'income', and 'product_category'. For 'age', use median imputation. For 'income', use a regression imputer (e.g., IterativeImputer from sklearn). For 'product_category', fill with the mode. Write the code and explain your choices."

Example Result:

from sklearn.impute import SimpleImputer, IterativeImputer

# median for age
imputer = SimpleImputer(strategy='median')
df['age'] = imputer.fit_transform(df[['age']])

# iterative for income
imp = IterativeImputer(max_iter=10, random_state=0)
df['income'] = imp.fit_transform(df[['income']])

# mode for category
imputer_cat = SimpleImputer(strategy='most_frequent')
df['product_category'] = imputer_cat.fit_transform(df[['product_category']])

The model explains that median is robust to outliers, iterative imputation uses correlations between features, and mode is appropriate for categorical data.

1.3 Outlier Detection

Task: Detect and handle outliers in a numerical column.

Prompt:
"Using the IQR method, identify outliers in the 'spending' column of my DataFrame. Show me the code to flag them, and then suggest whether to remove or cap them, considering that this is a customer segmentation project."

Example Result:

Q1 = df['spending'].quantile(0.25)
Q3 = df['spending'].quantile(0.75)
IQR = Q3 - Q1
lower_bound = Q1 - 1.5 * IQR
upper_bound = Q3 + 1.5 * IQR
outliers = df[(df['spending'] < lower_bound) | (df['spending'] > upper_bound)]
print(f"Number of outliers: {len(outliers)}")

The model suggests capping the outliers at the 99th percentile rather than removing them, because they might represent valuable high-value customers.

1.4 Feature Engineering from Datetime

Task: Extract useful features from a datetime column.

Prompt:
"I have a column 'purchase_date' with datetime values. Generate code to extract the following features: day of week, month, year, and days since the most recent purchase in the dataset. Explain why these might be useful for a churn prediction model."

Example Result:

df['purchase_date'] = pd.to_datetime(df['purchase_date'])
df['day_of_week'] = df['purchase_date'].dt.dayofweek
df['month'] = df['purchase_date'].dt.month
df['year'] = df['purchase_date'].dt.year
df['days_since_last_purchase'] = (df['purchase_date'].max() - df['purchase_date']).dt.days

The model explains that day of week captures weekly patterns, month captures seasonality, and recency is a strong predictor of churn.

2. Exploratory Data Analysis (EDA)

2.1 Automated EDA Report

Task: Generate a comprehensive EDA report with visualizations.

Prompt:
"Create an EDA report for the 'customer_data.csv' dataset. Include: distribution plots for all numerical columns, count plots for categorical columns, a correlation heatmap, and a pairplot for the top 5 numerical features by correlation with the target 'churn'. Use seaborn and matplotlib. Also write a brief interpretation of each plot."

Example Result: The model generates a complete code block that produces the plots, followed by interpretations like 'The correlation heatmap shows that 'tenure' and 'monthly_charges' are strongly correlated with churn (r = -0.35 and 0.25, respectively). Customers with short tenure are more likely to churn...'

2.2 Identifying Data Skewness

Task: Detect and correct skewness in features.

Prompt:
"Check the skewness of all numerical features in my DataFrame. For features with skewness > 1 or < -1, suggest and apply a transformation (log, Box-Cox, or Yeo-Johnson). Write the code and justify your transformation choice."

Example Result:

from scipy.stats import skew
from sklearn.preprocessing import PowerTransformer

skewness = df.select_dtypes(include=['float64', 'int64']).apply(lambda x: skew(x.dropna()))
print(skewness[abs(skewness) > 1])

pt = PowerTransformer(method='yeo-johnson')  # works with negative values too
df_transformed = pt.fit_transform(df[['income', 'total_charges']])

The model explains that Yeo-Johnson is preferable because it handles both positive and negative values, unlike Box-Cox which requires positive data.

3. Model Building and Evaluation

3.1 Train-Test Split and Baseline Model

Task: Split data and build a baseline model.

Prompt:
"Split my data into train and test sets (80/20) using stratification on the target column 'churn'. Then train a logistic regression model as a baseline. Print the accuracy, precision, recall, and F1-score on the test set. Also plot the ROC curve."

Example Result:

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, roc_curve, auc
import matplotlib.pyplot as plt

X = df.drop('churn', axis=1)
y = df['churn']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)

model = LogisticRegression(max_iter=1000)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print(classification_report(y_test, y_pred))

fpr, tpr, _ = roc_curve(y_test, model.predict_proba(X_test)[:,1])
plt.plot(fpr, tpr)
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('ROC Curve')
plt.show()

The model explains that logistic regression serves as a simple baseline, and the classification report shows a baseline performance to beat with more complex models.

3.2 Hyperparameter Tuning with GridSearchCV

Task: Find optimal hyperparameters for a Random Forest.

Prompt:
"I want to tune a Random Forest classifier using GridSearchCV. The parameter grid should include 'n_estimators' (50, 100, 200), 'max_depth' (None, 10, 20), and 'min_samples_split' (2, 5, 10). Use 5-fold cross-validation and scoring='f1'. Write the code and show the best parameters and the corresponding CV score."

Example Result:

from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import GridSearchCV

param_grid = {
    'n_estimators': [50, 100, 200],
    'max_depth': [None, 10, 20],
    'min_samples_split': [2, 5, 10]
}

grid = GridSearchCV(RandomForestClassifier(random_state=42), param_grid, cv=5, scoring='f1')
grid.fit(X_train, y_train)
print(grid.best_params_)
print(grid.best_score_)

The model suggests using the best estimator directly, e.g., best_model = grid.best_estimator_.

3.3 Feature Importance Analysis

Task: Determine which features are most important for the model.

Prompt:
"From the trained Random Forest model above, extract feature importances. Show them in a bar plot, and list the top 10 features with their importance scores. Also suggest whether any features can be dropped."

Example Result:

importances = grid.best_estimator_.feature_importances_
feature_names = X.columns
sorted_idx = importances.argsort()[::-1]
plt.barh(feature_names[sorted_idx][:10], importances[sorted_idx][:10])
plt.show()

The model notes that features with importance < 0.01 can be dropped to simplify the model without significant loss.

3.4 Handling Imbalanced Data

Task: Deal with class imbalance in a binary classification problem.

Prompt:
"My target column 'churn' has only 15% positive cases. Use SMOTE to oversample the minority class in the training set, then train a Random Forest and evaluate on the original test set. Compare the F1-score with the baseline model."

Example Result:

from imblearn.over_sampling import SMOTE
from imblearn.pipeline import Pipeline as ImbPipeline

smote = SMOTE(random_state=42)
model = RandomForestClassifier(random_state=42)

pipeline = ImbPipeline([('smote', smote), ('classifier', model)])
pipeline.fit(X_train, y_train)
y_pred = pipeline.predict(X_test)
print(classification_report(y_test, y_pred))

The model explains that SMOTE creates synthetic samples of the minority class, potentially improving recall without overfitting.

4. Model Interpretation and Explainability

4.1 SHAP Values for Feature Impact

Task: Understand how each feature affects individual predictions.

Prompt:
"Use SHAP to explain the predictions of my trained Random Forest classifier. Generate a summary plot (beeswarm) and a bar plot of mean

|SHAP| values. Interpret the plots: which features are most important and how do they impact the prediction direction?"

Example Result:

import shap

explainer = shap.TreeExplainer(grid.best_estimator_)
shap_values = explainer.shap_values(X_test)
shap.summary_plot(shap_values, X_test, plot_type="bar")
shap.summary_plot(shap_values, X_test)

The model interprets the plot: 'The bar plot shows that 'tenure' contributes most to the prediction. The beeswarm plot shows that low tenure values push the prediction towards churn (positive SHAP), while high tenure values push towards non-churn.'

4.2 LIME for Local Explanations

Task: Explain a single prediction in a human-friendly way.

Prompt:
"Take the first instance from X_test and explain its prediction using LIME. Provide the code and a textual explanation of the top contributing features."

Example Result:

import lime
import lime.lime_tabular

explainer = lime.lime_tabular.LimeTabularExplainer(
    training_data=X_train.values,
    feature_names=X_train.columns,
    class_names=['No Churn', 'Churn'],
    mode='classification'
)
exp = explainer.explain_instance(X_test.iloc[0].values, grid.best_estimator_.predict_proba, num_features=5)
exp.show_in_notebook()

The model outputs a textual summary: 'The model predicts churn for this customer with 73% probability. The top factors are: monthly_charges > $80, tenure < 12 months, and contract_type = month-to-month.'

5. Model Deployment and Production

5.1 Saving and Loading the Model

Task: Persist the trained model to disk for later use.

Prompt:
"I've finished training my Random Forest model. Save it to a file 'churn_model.pkl' using joblib, and then show code to load it back and make a prediction on a new sample."

Example Result:

import joblib

joblib.dump(grid.best_estimator_, 'churn_model.pkl')
# Later
loaded_model = joblib.load('churn_model.pkl')
new_sample = X_test.iloc[0:1]
prediction = loaded_model.predict(new_sample)
print(prediction)

5.2 Creating a REST API with FastAPI

Task: Wrap the model in a simple REST API for serving predictions.

Prompt:
"Write a FastAPI application that loads the 'churn_model.pkl' and exposes a POST endpoint '/predict' that accepts a JSON object with features and returns the predicted class. Include input validation using Pydantic models."

Example Result:

from fastapi import FastAPI
from pydantic import BaseModel
import joblib
import pandas as pd

app = FastAPI()
model = joblib.load('churn_model.pkl')

class CustomerFeatures(BaseModel):
    tenure: float
    monthly_charges: float
    total_charges: float
    contract_type: str

@app.post('/predict')
def predict(features: CustomerFeatures):
    df = pd.DataFrame([features.dict()])
    pred = model.predict(df)[0]
    return {'churn_prediction': int(pred)}

The model notes that in a real project, you'd need to include the same preprocessing steps (e.g., one-hot encoding) in the API.

5.3 Dockerizing the API

Task: Containerize the FastAPI app for deployment.

Prompt:
"Create a Dockerfile for the FastAPI app. It should use a Python 3.9 base image, install dependencies from a requirements.txt, copy the app code and model file, and expose port 8000. Also provide a docker-compose.yml for local development."

Example Result:

FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
# docker-compose.yml
version: '3'
services:
  api:
    build: .
    ports:
      - "8000:8000"

5.4 Monitoring Model Drift

Task: Detect when the model's performance degrades in production.

Prompt:
"Explain how to monitor model drift in a production environment. Specifically, describe two types: data drift and concept drift. Provide Python code using the Evidently library to generate a drift report on a new batch of data compared to the training data."

Example Result: The model explains that data drift occurs when the input distribution changes, while concept drift occurs when the relationship between features and target changes. It then provides code using evidently to compare datasets and produce a JSON report.

6. Specialized Prompts for Common Tasks

6.1 Time Series Forecasting

Task: Build a simple ARIMA model for monthly sales data.

Prompt:
"I have monthly sales data in a CSV with columns 'date' and 'sales'. Fit an ARIMA model to forecast the next 6 months. Use the statsmodels library. Show the code to load the data, set the index, fit the model, and plot the forecast with confidence intervals."

Example Result:

import pandas as pd
from statsmodels.tsa.arima.model import ARIMA
import matplotlib.pyplot as plt

df = pd.read_csv('sales.csv', parse_dates=['date'], index_col='date')
model = ARIMA(df['sales'], order=(1,1,1))
fit = model.fit()
forecast = fit.get_forecast(steps=6)
mean = forecast.predicted_mean
conf_int = forecast.conf_int()
plt.plot(df.index, df['sales'], label='Actual')
plt.plot(mean.index, mean, label='Forecast')
plt.fill_between(mean.index, conf_int.iloc[:,0], conf_int.iloc[:,1], alpha=0.2)
plt.legend()
plt.show()

6.2 Natural Language Processing (NLP)

Task: Classify customer reviews as positive or negative.

Prompt:
"I have a list of customer reviews in a text file. Use a pre-trained BERT model from Hugging Face to perform sentiment analysis. Write code to load the model, preprocess the texts, and output a label and confidence score for each review."

Example Result:

from transformers import pipeline

classifier = pipeline('sentiment-analysis')
reviews = ["I love this product!", "This is terrible."]
results = classifier(reviews)
for review, result in zip(reviews, results):
    print(f"{review} -> {result['label']} ({result['score']:.2f})")

6.3 Recommender Systems

Task: Build a simple collaborative filtering model.

Prompt:
"I have a user-item rating matrix in a CSV (columns: user_id, item_id, rating). Implement a matrix factorization model using the surprise library. Split the data into train/test, train with SVD, and evaluate with RMSE."

Example Result:

from surprise import SVD, Dataset, Reader, accuracy
from surprise.model_selection import train_test_split

reader = Reader(line_format='user item rating', sep=',')
data = Dataset.load_from_file('ratings.csv', reader=reader)
trainset, testset = train_test_split(data, test_size=0.2)
algo = SVD()
algo.fit(trainset)
predictions = algo.test(testset)
accuracy.rmse(predictions)

6.4 Anomaly Detection

Task: Detect fraudulent transactions using Isolation Forest.

Prompt:
"Using the 'creditcard.csv' dataset, build an Isolation Forest model to detect anomalies. Since the dataset is highly imbalanced, evaluate using precision, recall, and F1-score on the minority class. Provide the code and interpretation."

Example Result:

from sklearn.ensemble import IsolationForest
from sklearn.metrics import classification_report

df = pd.read_csv('creditcard.csv')
X = df.drop('Class', axis=1)
y = df['Class']
model = IsolationForest(contamination=0.01, random_state=42)
model.fit(X)
y_pred = model.predict(X)
y_pred = [1 if p == -1 else 0 for p in y_pred]
print(classification_report(y, y_pred))

7. Data Engineering Prompts

7.1 Writing ETL Pipelines

Task: Create an ETL pipeline to fetch data from an API, clean it, and load it into a database.

Prompt:
"Write a Python script that extracts data from the JSONPlaceholder API (https://jsonplaceholder.typicode.com/posts), transforms it by adding a 'word_count' column, and loads it into a SQLite database. Use pandas and sqlite3. Include error handling and logging."

Example Result:

import requests
import pandas as pd
import sqlite3
import logging

logging.basicConfig(level=logging.INFO)

def extract():
    response = requests.get('https://jsonplaceholder.typicode.com/posts')
    response.raise_for_status()
    return pd.DataFrame(response.json())

def transform(df):
    df['word_count'] = df['body'].apply(lambda x: len(x.split()))
    return df

def load(df):
    conn = sqlite3.connect('posts.db')
    df.to_sql('posts', conn, if_exists='replace', index=False)
    conn.close()

if __name__ == '__main__':
    df = extract()
    df = transform(df)
    load(df)
    logging.info('ETL completed')

7.2 Working with Large Datasets (Dask)

Task: Process a dataset that doesn't fit into memory.

Prompt:
"I have a 10GB CSV file. Show me how to use Dask to read it, compute the mean of a column, and group by a categorical column without loading the entire file into memory."

Example Result:

import dask.dataframe as dd

df = dd.read_csv('large_file.csv', blocksize='100MB')
print(df['value'].mean().compute())
print(df.groupby('category')['value'].mean().compute())

8. Experimental Tracking and Collaboration

8.1 Using MLflow for Experiment Tracking

Task: Log parameters, metrics, and models in MLflow.

Prompt:
"Set up an MLflow experiment to track the Random Forest model training. Log the hyperparameters, the F1-score, and the model artifact. Show the code for a simple tracking run."

Example Result:

import mlflow
import mlflow.sklearn

with mlflow.start_run():
    mlflow.log_param('n_estimators', 100)
    mlflow.log_param('max_depth', 10)
    mlflow.log_metric('f1', f1_score(y_test, y_pred))
    mlflow.sklearn.log_model(grid.best_estimator_, 'model')

9. Prompt Engineering for Data Science

9.1 Generating Synthetic Data

Task: Create a synthetic dataset for testing a model.

Prompt:
"Generate a synthetic dataset with 1000 rows and 5 features: 'age' (integer 18-80), 'income' (float 20k-150k), 'education' (categorical: High School, Bachelor, Master, PhD), 'city' (one of New York, London, Tokyo), and 'target' (binary, correlated with age and income). Use numpy and pandas. Ensure the target has a reasonable class imbalance (e.g., 30% positive)."

Example Result:

import numpy as np
import pandas as pd

np.random.seed(42)

n = 1000
age = np.random.randint(18, 80, n)
income = np.random.uniform(20000, 150000, n)
education = np.random.choice(['High School', 'Bachelor', 'Master', 'PhD'], n, p=[0.3, 0.4, 0.2, 0.1])
city = np.random.choice(['New York', 'London', 'Tokyo'], n, p=[0.5, 0.3, 0.2])
# target: higher age and income -> higher probability
prob = 1 / (1 + np.exp(-(0.05*age + 0.00002*income - 3)))
target = np.random.binomial(1, prob)

df = pd.DataFrame({'age': age, 'income': income, 'education': education, 'city': city, 'target': target})

9.2 Explaining Concepts to a Non-Technical Audience

Task: Get a plain-English explanation of a complex algorithm.

Prompt:
"Explain the concept of gradient boosting in simple terms, using an analogy. Keep it under 150 words, and avoid mathematical notation."

Example Result:
"Gradient boosting is like assembling a team of weak learners, where each new member focuses on the mistakes of the previous ones. Imagine you're trying to guess someone's age. Your first guess might be wildly off. The next person looks at where you went wrong and adjusts. Each subsequent person refines the guess further. In the end, the combined predictions of the team are much more accurate than any individual guess. This is how gradient boosting works: it sequentially adds models that correct the errors of the existing ensemble."

10. Advanced Prompts for Specific Scenarios

10.1 AutoML with TPOT

Task: Automatically search for the best machine learning pipeline.

Prompt:
"Use TPOT to find an optimal pipeline for my classification problem. Set generations=3, population_size=10, and scoring='f1'. Show the code and the best pipeline found."

Example Result:

from tpot import TPOTClassifier

tpot = TPOTClassifier(generations=3, population_size=10, scoring='f1', random_state=42)
tpot.fit(X_train, y_train)
print(tpot.score(X_test, y_test))
tpot.export('best_pipeline.py')

10.2 Code Review and Optimization

Task: Have the LLM review your code for efficiency and best practices.

Prompt:
"Here's a pandas code snippet I wrote. Please review it for performance, readability, and correctness. Suggest improvements.

df = pd.read_csv('data.csv')
for col in df.columns:
    if df[col].dtype == 'object':
        df[col] = df[col].fillna('missing')
        df[col] = df[col].astype('category')

"

Example Result: The model suggests using df.fillna('missing') vectorized, and using pd.Categorical for memory, and points out that astype('category') is fine but could be done in one line.

11. Data Visualization Prompts

11.1 Creating a Dashboard with Plotly

Task: Build an interactive dashboard for exploring the dataset.

Prompt:
"Create an interactive Plotly dashboard with two plots: a scatter plot of 'income' vs 'age' colored by 'churn', and a bar chart of average 'monthly_charges' by 'contract_type'. Use the 'customer_data.csv' dataset. Output the code with a brief explanation."

Example Result:

import plotly.express as px

df = pd.read_csv('customer_data.csv')
fig1 = px.scatter(df, x='age', y='income', color='churn', title='Income vs Age by Churn')
fig2 = px.bar(df.groupby('contract_type')['monthly_charges'].mean().reset_index(), 
              x='contract_type', y='monthly_charges', title='Average Monthly Charges by Contract')
fig1.show()
fig2.show()

12. Best Practices and Pitfalls

12.1 Data Leakage Prevention

Task: Ensure your pipeline doesn't leak information from the test set.

Prompt:
"Explain data leakage in machine learning and provide a checklist to avoid it. Give an example of a common mistake, such as scaling the entire dataset before splitting, and show the correct way."

Example Result: The model explains that scaling before splitting lets the scaler 'see' the test set, thus leaking information. The correct way is to fit the scaler on the training set only, then transform both train and test. It provides code:

from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

12.2 Version Control for Data Science

Task: Manage code and data versioning with DVC.

Prompt:
"How do I use DVC (Data Version Control) to track my datasets and models? Provide the basic commands to initialize DVC, add a data file, and commit."

Example Result:

dvc init
dvc add data/customer_data.csv
git add data/customer_data.csv.dvc .dvc/config
 git commit -m "add data"

13. Final Thoughts and Further Resources

These 30 prompts cover the core stages of a data science project, but they're just the beginning. The key to effective prompt engineering is to be specific: include dataset details, desired output format, and any constraints. Treat the LLM as a pair programmer — you wouldn't say 'write code' without context, so don't do that with a prompt either.

As you integrate prompts into your workflow, you'll discover that many tasks can be accelerated, from data cleaning to model deployment. However, always remember to validate the outputs: use your domain knowledge to check for correctness, and run proper evaluation metrics. The LLM is a powerful assistant, but you are the scientist.

If you want to dive deeper, I recommend checking out the official documentation of the libraries mentioned here (pandas, scikit-learn, FastAPI) and the OpenAI prompt engineering guide. Happy modeling!

← All posts

Comments