← IndexEntry № 064·data

Analyze a Dataset With Pandas Step-by-Step

Generate step-by-step Pandas EDA code covering nulls, outliers, and a business question.

Optimized for
ClaudeChatGPT
§ When to use this

This prompt makes the model write commented, step-by-step pandas code for a real exploratory analysis on your DataFrame — profiling, null handling, IQR outlier detection, and then answering a specific business question. Reach for it when you have a dataset loaded and want a defensible analysis pipeline rather than a wall of unexplained code. Listing your actual columns and types is what lets it pick the right operations instead of guessing at your schema.

§ The Prompt— fill in the fields, then copy or open in a tool
§ Customize0/2 fields filled
your prompt — fill the fields above
You are a data scientist. I have a pandas DataFrame called 'df' with these columns: [LIST COLUMN NAMES AND TYPES]. Write Python code to: (1) perform an EDA (shape, dtypes, null counts, basic stats), (2) identify and handle missing values, (3) detect and summarize outliers using IQR, (4) answer this specific question: '[BUSINESS QUESTION]'. Add a comment above each block explaining what it does and why.
Open with your prompt →ChatGPTClaudeSends your filled-in prompt straight into a new chat.
§ Example Output

What you can expect back

# 1. EDA — understand shape, types, and where data is missing
print(df.shape)
print(df.dtypes)
print(df.isnull().sum())
print(df.describe(include='all'))

# 2. Handle missing values — drop rows missing the key fields, flag amount nulls
df = df.dropna(subset=['region', 'refunded'])
df['amount'] = df['amount'].fillna(df['amount'].median())  # median resists outliers

# 3. Outliers in amount via IQR — summarize rather than auto-delete
q1, q3 = df['amount'].quantile([0.25, 0.75])
iqr = q3 - q1
low, high = q1 - 1.5*iqr, q3 + 1.5*iqr
outliers = df[(df['amount'] < low) | (df['amount'] > high)]
print(f"{len(outliers)} outlier orders ({len(outliers)/len(df):.1%})")

# 4. Refund rate by region
rates = df.groupby('region')['refunded'].mean().sort_values(ascending=False)
print(rates)
# Meaningfulness: compare top region's rate to overall and check sample size per region
print(df['region'].value_counts())

Illustrative example — your results will vary by tool and inputs.

§ Pro Tips

Get sharper results

  • 01Get the exact dtypes right (especially datetime vs. object and category vs. string) because the code branches on them — a date stored as text will break any time-based step.
  • 02Tell it your row count order of magnitude; for millions of rows it should suggest vectorized or sampled approaches instead of operations that quietly blow up memory.
  • 03Specify whether outliers should be removed, capped, or just reported, since auto-deleting them can silently distort the very business answer you're after.
  • 04Ask for the statistical test by name (e.g. a chi-square or two-proportion z-test) when the question is about whether a difference is 'meaningful,' so it quantifies significance instead of eyeballing it.
  • 05Request that it print intermediate results after each block so you can sanity-check the data as the pipeline runs rather than trusting the final number blind.
§ Variations

Adapt it for your case

Add visualizations

Append 'include matplotlib/seaborn plots for distributions and the final answer' to get charts alongside the tables.

Polars instead of pandas

Replace 'pandas DataFrame' with 'Polars DataFrame' and ask for idiomatic Polars expressions for speed on large data.

Reusable analysis function

Ask it to 'wrap the pipeline in a documented function that takes df and the business question's columns as parameters.'

Best For — Roles
Use For — Tasks
Tags#pandas#python#data-analysis
§ FAQ

Common questions

Will the code run without errors on my data?

Only if your real columns and dtypes match what you described. Mismatches — a stringified date, an unexpected null — are the usual cause of breakage, so verify the schema first.

Is dropping or filling nulls the right call for my dataset?

The model picks a reasonable default, but the correct strategy depends on why data is missing. State the cause if you know it, or ask it to explain the tradeoffs of each option.

Does IQR catch all outliers?

IQR is a solid general method but assumes a roughly unimodal distribution. For skewed or multimodal data, ask it to also try z-scores or a domain-specific threshold.

§ Related Entries

You may also need