10 Prompts for Data Science: Pandas, Matplotlib, and Seaborn

10 Prompts for Data Science: Pandas, Matplotlib, and Seaborn

If you've ever spent more time wrestling with error messages than actually exploring your data, you know the pain. Data science is not just about writing code; it's about asking the right questions and generating the right code to answer them. Large language models can be a powerful ally in this process, but only if you give them well-structured prompts.

This article is a practical collection of 10 prompts that cover the most common data analysis and visualization tasks using three of Python's most popular libraries: Pandas, Matplotlib, and Seaborn. Each prompt is ready to copy, paste, and adapt to your own dataset. I've based these prompts on the official documentation and on real-world patterns used in data science work. Whether you're a beginner or an experienced analyst, you'll find something to speed up your work.

How to Use These Prompts

The prompts are designed for LLMs that can generate Python code. You'll need to replace the generic df with your actual DataFrame name and give the AI a sample of your data structure (e.g., the output of df.head()). The more context about column names and data types you provide, the more precise the generated code will be. For example, you can paste the output of df.head().to_string() right after the prompt. After receiving a response, always run the code on a small subset of your data first to verify correctness.

Here is a quick overview of the prompts in this article:

# Prompt Focus Libraries Best For
1 Data Profiling Pandas Getting an overview
2 Missing Data Imputation Pandas Cleaning data
3 Filtering & Selection Pandas Subsetting rows
4 Grouped Aggregation Pandas Summary statistics
5 Reshaping Data Pandas Tidy data
6 Line Plot Matplotlib Time series
7 Grouped Bar Chart Seaborn Comparing groups
8 Distribution Analysis Seaborn Checking normality
9 Correlation Heatmap Seaborn + Matplotlib Finding relationships
10 Pairplot Seaborn Multivariate EDA

These prompts are ordered in a typical workflow: first, understand your data; second, clean it; third, transform it; then visualize. Some tasks overlap, so feel free to jump to the section you need.

1. Data Profiling and Overview

Task: Quickly understand the structure of a dataset.

Prompt:

I have a Pandas DataFrame named `df`. Write Python code to display:
- the first 5 rows,
- column names and data types,
- the number of missing values per column,
- basic descriptive statistics for numeric columns,
- the number of unique values in each column.
Use `df.head()`, `df.info()`, `df.isnull().sum()`, `df.describe()`, and `df.nunique()`.
Then explain the output in simple terms.

Example usage: This is often the first code you run when you receive a new dataset. For instance, suppose you load a customer churn dataset with 10,000 rows and 20 columns. The output of df.info() gives you a concise summary of the data types (e.g., int64, float64, object) and memory usage. This prompt will produce a clear report you can use to decide next steps.

Expected output: A summary that lists missing counts for each column, e.g., age: 0, income: 2500, etc. This helps you plan data cleaning.

According to the pandas documentation, df.info() is the recommended way to get a concise summary of a DataFrame.

2. Missing Data Imputation

Task: Handle missing values intelligently.

Prompt:

Given a Pandas DataFrame `df`, write code to:
- find columns with missing values,
- for numeric columns, fill missing values with the column median,
- for categorical columns, fill missing values with the mode,
- create a new column `missing_count` that counts the number of missing values in each row.
Explain each step and justify your choices.

Example usage: Consider a data set where the age column has some missing values and the city column contains a few NaN values. Using the median for age is safer than the mean when there are outliers. For city, the mode fills in the most common city. The new missing_count column is useful for spotting rows that have multiple missing values, which you might choose to drop.

This approach aligns with the advice in the pandas user guide on missing data, which suggests several strategies, including fill and interpolate.

3. Filtering and Conditional Selection

Task: Extract subsets of data based on conditions.

Prompt:

From the DataFrame `df`, write Pandas code to:
- select rows where the column `age` is greater than 30,
- select rows where `city` is either "New York" or "London",
- select rows where `salary` is between 50000 and 100000,
- combine these conditions with `&` and `|` operators.
Then show how to use `df.loc` and `df.query` for the same task.

Example usage: Suppose you are analyzing employee data and want to filter for senior employees in certain cities. The query method is especially useful because it allows SQL-like syntax, making the code more readable. For example, df.query("age > 30 and city in ['New York', 'London']") returns the same result as the & version.

The loc method is the standard way to access rows and columns by label, as described in the pandas documentation.

4. Grouped Aggregation with groupby

Task: Summarize data by groups.

Prompt:

Using Pandas, write code to calculate the average, sum, and count of the `sales` column, grouped by the `region` column in `df`. Also, create a pivot table that shows the average sales for each `region` and `product`. Use `agg()` with a dictionary to compute multiple statistics at once. Explain the difference between `groupby` and `pivot_table`.

Example usage: A sales manager might ask: "What are the total sales per region?" This prompt produces code that quickly answers that. For example, df.groupby("region")["sales"].agg(["mean", "sum", "count"]) returns a concise table. A pivot table is a multi-index version of the same idea, useful when you need two grouping dimensions.

The groupby operation is one of the most powerful tools in pandas and is extensively documented in the pandas user guide on groupby.

5. Reshaping Data: melt and pivot

Task: Convert data between wide and long formats.

Prompt:

Given a DataFrame `df` in wide format with columns `id`, `Q1`, `Q2`, `Q3`, write Pandas code to:
- convert it to long format using `pd.melt`,
- convert it back to wide format using `pivot`,
- explain when each format is appropriate for analysis and visualization.

Example usage: Suppose you have survey data where each question is a column (Q1, Q2, Q3). To plot all questions on a single chart, you need the long format. pd.melt creates a row per question, making it easy to use in Seaborn. Converting back with pivot is useful for preparing a summary table.

For a detailed explanation, check the pandas documentation on reshaping.

6. Basic Line Plot with Matplotlib

Task: Create a professional time-series line chart.

Prompt:

Write Matplotlib code to plot a line chart from the DataFrame `df` with columns `date` and `value`.
- Set the figure size to (10, 5),
- add a title "Value Over Time",
- label the axes,
- add a grid,
- format the x-axis date ticks to show only the year.
Use `plt.plot`, `plt.xlabel`, `plt.ylabel`, `plt.title`, `plt.grid`, and `plt.subplots` from matplotlib.

Example usage: Imagine you have monthly website traffic data. This prompt generates a clean line chart that clearly shows trends over years. The date tick formatting is useful when your data covers many years.

The Matplotlib documentation provides examples for date formatting and figure styling.

7. Customized Bar Chart with Hue (Seaborn)

Task: Create a grouped bar chart to compare categories across another category.

Prompt:

Using Seaborn, create a grouped bar chart that shows the average `sales` for each `region` and `product`.
- Use `sns.barplot`,
- set `errorbar=None` to hide error bars,
- add value labels on top of each bar,
- style the plot with `sns.set_theme(style="whitegrid")`.
Write the complete code and explain each parameter.

Example usage: A retail company may want to compare average sales by region across product categories. The grouped bar chart makes this comparison visually immediate.

Seaborn is built on Matplotlib and simplifies statistical visualization. The Seaborn documentation is the authoritative source for its API.

8. Distribution Analysis with Histogram and KDE

Task: Understand the statistical distribution of a numeric column.

Prompt:

Write Python code using Seaborn to plot the distribution of the column `score` in `df`.
- Create a histogram with a kernel density estimate (KDE) overlay,
- add a vertical line at the mean and median,
- use a custom color palette,
- set the x-axis label to "Score" and the title to "Score Distribution".
Use `sns.histplot` with `kde=True`.

Example usage: This prompt is useful when you need to know if a variable is normally distributed, which is important for many statistical tests. For example, if the distribution is right-skewed, you may apply a log transformation.

histplot is part of Seaborn's distribution module, documented in the Seaborn API reference.

9. Correlation Heatmap

Task: Visualize correlations between numeric variables.

Prompt:

For the DataFrame `df`, write code to compute the correlation matrix of all numeric columns and display it as a heatmap using Seaborn.
- Use `df.corr()`,
- create the heatmap with `sns.heatmap`,
- set parameters: `annot=True`, `fmt=".2f"`, `cmap="coolwarm"`, `square=True`,
- rotate x and y labels by 45 degrees.
Add a title "Correlation Heatmap".

Example usage: Before building a regression model, you want to identify strongly correlated features to avoid multicollinearity. A heatmap shows at a glance that, for example, hours_studied and score have a correlation of 0.83.

Correlation matrices are widely used in feature selection and EDA. The Seaborn example gallery contains heatmap examples.

10. Pairplot for Multivariate Exploration

Task: Explore relationships between multiple variables at once.

Prompt:

Use Seaborn to create a pairplot of the columns `col1`, `col2`, `col3`, and `col4` in `df`, colored by the categorical column `group`.
- Set `diag_kind="kde"`,
- set `markers=["o", "s", "D"]` for different groups,
- add a title.
Explain how to interpret the diagonal plots and the off-diagonal scatter plots.

Example usage: If you have a dataset with four numeric predictors and a target class, a pairplot shows all pairwise scatter plots. You might notice, for example, that col1 and col2 are linearly separated by class, which is a strong signal for machine learning.

The Seaborn documentation for pairplot explains parameters like diag_kind and markers.


These ten prompts form a complete toolkit for everyday data work. Start with data profiling, move through cleaning and reshaping, and finish with visualization. The more you adapt these prompts to your own data, the more intuitive the process becomes. If this guide was useful, share it with your colleagues or bookmark it for your next project.

Remember, a prompt is just a starting point. Always review the generated code and adapt it to your style. The official documentation is your friend: pandas, matplotlib, seaborn. Happy coding!

← All posts

Comments