Analyze Sales Data with Python
Load, clean, and visualize messy sales data using pandas and matplotlib.
Introduction
30 Second Summary
Every business tracks its sales, but raw transaction data in a spreadsheet doesn't tell you which products actually make money. Before you can trust any number, someone has to dig through the data and spot the errors.
In this project, you will write a Python script that loads a messy CSV of sales transactions and catches hidden data quality problems. It produces professional charts showing which products drive the most revenue.
What You'll Build
You'll run your finished script and watch it print "Duplicate rows found: 4" in the terminal before two professional charts pop up on your screen showing the real revenue story.
By the end of this project, you'll have:
- A script that loads a sales dataset and prints formatted data to your terminal using pandas, letting you instantly see what you're working with.
- Clean, accurate revenue totals after catching duplicate rows and missing values that silently skew the numbers.
- Two professional charts saved as PNG files using matplotlib: a bar chart of revenue by product and a line chart of the monthly revenue trend.
- Secret Mission: Build a regional revenue breakdown with a grouped bar chart comparing products across regions.
Are there any prerequisites?
No prerequisites are needed. This project walks you through setting up all required tools and libraries. Basic math knowledge is helpful but not required.
Before We Start
Before we dive in, let's lock in what you're about to build and why it matters.
Set Up Your Python Environment
Before you can analyze any data, you need the right tools in place. Python handles the basics, but for working with tabular data and creating charts, you need two specialized libraries.
In this step, you'll install pandas and matplotlib, set up a project folder on your Desktop, and create a sample sales dataset to analyze.
In this step, get ready to:
- Install pandas and matplotlib using pip.
- Create a project folder with a sample sales dataset.
- Create an empty Python script file that you'll build on in the next steps.
Install pandas and matplotlib
pandas is the go-to Python library for working with tabular data like spreadsheets and CSV files. matplotlib turns that data into professional charts.
- In VS Code, open the integrated terminal by clicking **Terminal** in the top menu bar, then clicking **New Terminal**.
- Install both libraries at once by running this command:
pip install pandas matplotlib
What does this command do?
pip is Python's package manager. It downloads and installs libraries from the Python Package Index (PyPI). This single command installs both pandas and matplotlib along with all of their dependencies.
You should see download progress and a success message for each library.
Before you run the next command, what do you expect to see if both libraries installed correctly?
- Verify both libraries are working by running this command:
python -c "import pandas; import matplotlib; print('pandas', pandas.__version__); print('matplotlib', matplotlib.__version__)"
You should see both library names followed by their version numbers printed on separate lines, with no errors.
Seeing 'command not found' or an error?
- If pip is not found, try using pip3 instead. On some systems, Python 3's package manager is named pip3.
- If the verify command fails, try replacing python with python3 in the command.
- If you see a network error, check your internet connection and try running the install command again.
Help me troubleshoot my pandas and matplotlib installation.
Create the project folder and sample dataset
Every analysis project needs a dedicated folder to keep your data and scripts organized. You'll also create a sample sales dataset that you'll analyze throughout this project.
- Move to your Desktop by running this command:
cd ~/Desktop
- Create your project folder and move into it by running these commands:
mkdir sales-analysis
cd sales-analysis
- Open the sales-analysis folder in VS Code.
- Click File in the top menu bar.
- Click Open Folder.
- Navigate to your Desktop, select the sales-analysis folder, then click Open.
Seeing a trust dialog?
VS Code may ask if you trust the authors of the files in this folder. Click Yes, I trust the authors to continue.
VS Code reloads with the sales-analysis folder open. The Explorer sidebar on the left now shows your empty project folder.
- Create the dataset file by right-clicking in the empty area of the Explorer sidebar.
- Click New File.
- Type sales_data.csv and press Enter.
- Paste the following data into sales_data.csv:
Date,Product,Region,Units,Revenue
2024-01-15,Laptop,North,3,3600
2024-01-22,Headphones,South,10,500
2024-02-03,Laptop,East,2,2400
2024-02-14,Keyboard,North,15,750
2024-02-28,Monitor,West,4,1600
2024-03-05,Laptop,South,1,1200
2024-03-12,Headphones,North,8,400
2024-03-19,Mouse,East,,150
2024-04-02,Keyboard,West,12,600
2024-04-15,Monitor,North,6,2400
2024-04-22,Laptop,East,3,3600
2024-05-01,Headphones,South,5,250
2024-05-14,Keyboard,North,20,1000
2024-05-28,Mouse,West,25,625
2024-06-03,Monitor,East,3,
2024-06-17,Laptop,North,4,4800
2024-06-25,Headphones,East,12,600
- Paste these rows directly below the last line, continuing the same file:
2024-07-04,Keyboard,South,8,400
2024-07-18,Monitor,West,5,2000
2024-07-29,Mouse,North,,200
2024-08-05,Laptop,South,2,2400
2024-08-19,Headphones,West,6,300
2024-09-02,Keyboard,East,10,500
2024-09-15,Monitor,North,7,2800
2024-09-28,Mouse,South,30,750
2024-10-10,Laptop,West,3,3600
2024-10-22,Headphones,North,15,750
2024-11-05,Keyboard,South,,450
2024-11-18,Monitor,East,4,1600
2024-12-01,Mouse,West,20,500
2024-01-15,Laptop,North,3,3600
2024-02-03,Laptop,East,2,2400
2024-04-22,Laptop,East,3,3600
2024-06-17,Laptop,North,4,4800
What's in this dataset?
This CSV file contains 34 rows of sales transactions across five products (Laptop, Headphones, Keyboard, Monitor, Mouse) and four regions (North, South, East, West).
Each row records the date, product name, region, number of units sold, and revenue. The data spans all 12 months of 2024. You might notice it looks clean at a glance, but there are hidden quality issues lurking inside that you'll uncover later.
- Save sales_data.csv by pressing Cmd+S (macOS) or Ctrl+S (Windows).
- Open a new terminal in VS Code by clicking Terminal in the top menu bar, then clicking New Terminal.
- Confirm the file was created by running:
ls
You should see sales_data.csv listed in the output.
Don't see the file?
- Make sure you saved the file. An unsaved file shows a dot or circle on its tab in VS Code.
- Check that your terminal is in the sales-analysis folder. The terminal prompt should show the folder name. If not, close the terminal and open a new one from the Terminal menu.
Help me find my sales_data.csv file in VS Code.
✔️ Awesome, I've got everything!
Great. Make sure you've saved sales_data.csv before moving on.
ⓧ I'd like to double check the full code
Your sales_data.csv file has 35 lines total. Scroll through and confirm:
- Line 1 is the header row: Date,Product,Region,Units,Revenue.
- The first data chunk (from the first CodeBlock) runs from line 2 through line 18, starting with 2024-01-15,Laptop,North and ending with 2024-06-25,Headphones,East.
- The second data chunk (from the second CodeBlock) runs from line 19 through line 35, starting with 2024-07-04,Keyboard,South and ending with 2024-06-17,Laptop,North.
- There are no blank lines between the two chunks. The data rows sit one after another with no gaps.
Create the analysis script file
- Right-click in the empty area of the Explorer sidebar again.
- Click New File.
- Type analyze_sales.py and press Enter.
- Leave this file empty for now. You'll start writing your analysis code in the next step.
- Confirm both files exist by running this command in the terminal:
ls
You should see both analyze_sales.py and sales_data.csv listed in the output.
Only seeing one file?
- Check the Explorer sidebar in VS Code. Both files should appear there under the sales-analysis heading.
- If a file is missing, repeat the right-click, New File process. Make sure you spell the filename exactly as shown, including the underscore.
Help me create files in my VS Code project folder.
Your environment is ready. You've got your libraries installed, your dataset loaded, and your script file waiting. Next up, you'll load that CSV into Python and see what your data actually looks like.
Load and Explore Your Data
Your Python environment is set up with pandas and matplotlib ready to go. Now it's time to get your sales data into Python and start exploring it.
Before you can analyze anything, you need to see what you're working with. This is the first thing every data scientist does with a new dataset.
In this step, get ready to:
- Load your sales CSV file into Python and see the first 10 rows printed in your terminal.
- Inspect the dataset's structure, column types, and basic statistics like averages and totals.
Load the CSV and print the first rows
pandas lets you load a CSV file into a structure called a DataFrame. A DataFrame organizes your data into rows and columns, similar to a spreadsheet.
- In VS Code, open analyze_sales.py by clicking on it in the Explorer sidebar on the left.
- Add the following code to the empty file:
import pandas as pd
# Load the data
df = pd.read_csv("sales_data.csv")
# Explore the data
print("First 10 rows:")
print(df.head(10))
What does this code do?
- import pandas as pd brings in the pandas library and gives it the shorthand name pd. This is the standard convention in every pandas tutorial and codebase.
- pd.read_csv("sales_data.csv") reads the CSV file and loads it into a DataFrame called df.
- df.head(10) returns the first 10 rows so you can quickly eyeball the data without printing the entire file.
- Save analyze_sales.py by pressing Cmd+S (macOS) or Ctrl+S (Windows).
- Run the script by entering this command in your terminal:
python analyze_sales.py
You should see a neatly formatted table with 10 rows of sales data, including columns for Date, Product, Region, Units, and Revenue.
Seeing an error?
- If you see FileNotFoundError, your terminal is not inside the sales-analysis folder. Run cd sales-analysis to move into it, then re-run the script.
- If you see ModuleNotFoundError, pandas was not installed correctly. Run pip install pandas again and then re-run the script.
- Help me debug my analyze_sales.py script
Inspect the dataset structure and statistics
Seeing the first few rows is a good start, but you also need to know the shape of the full dataset. How many rows does it have? Are there any missing values? What are the typical ranges for the numbers?
- In analyze_sales.py, add the following code below the print(df.head(10)) line:
print("\nDataset info:")
df.info()
print("\nBasic statistics:")
print(df.describe())
What does this code do?
- df.info() shows each column name, how many non-null values it has, and the data type. It prints directly to the terminal on its own, so no print() wrapper is needed.
- df.describe() calculates summary statistics for numeric columns: count, mean, min, max, and percentiles. This gives you a quick feel for the scale of your numbers.
- Save analyze_sales.py.
Before you run the script again, what new sections do you expect to see in the output compared to last time?
- Run the script again to find out:
python analyze_sales.py
After the familiar first 10 rows, you now see two new sections. The "Dataset info" block shows 34 entries across 5 columns, with data types and non-null counts for each column. The "Basic statistics" block shows the count, mean, min, and max for the Units and Revenue columns.
Output looks wrong?
- Make sure you added the new code below the existing print(df.head(10)) line, not above it or inside it.
- Check that each print statement has matching opening and closing parentheses.
- Help me fix my analyze_sales.py output
✔️ Awesome, I've got everything!
Great. Double check you've saved analyze_sales.py and you're ready to move on.
ⓧ I'd like to double check the full code
Here is the complete analyze_sales.py file so far. Compare it with yours and make sure everything matches.
import pandas as pd
# Load the data
df = pd.read_csv("sales_data.csv")
# Explore the data
print("First 10 rows:")
print(df.head(10))
print("\nDataset info:")
df.info()
print("\nBasic statistics:")
print(df.describe())
You can now load and explore a dataset with Python. Next up, you'll use this data to answer a real business question: which product makes the most money?
Analyze Revenue by Product
In the last step, you loaded the sales dataset and explored its shape. You saw 34 entries across 5 columns, plus summary statistics for the numeric fields.
Now it's time to answer a core business question: which product brings in the most revenue? You'll use one of pandas' most powerful features to group your data and calculate totals.
In this step, get ready to:
- Calculate revenue totals for each product using groupby.
- Print the total revenue and row count for the full dataset.
Group and sum revenue by product
The .groupby() method lets you split a DataFrame into groups based on a column, then run a calculation on each group. Think of it like sorting a pile of receipts by product name, then adding up the total for each pile.
- Add the following code to the bottom of analyze_sales.py:
# Group transactions by product and calculate totals
print("\n--- Revenue Analysis ---")
revenue_by_product = df.groupby("Product")["Revenue"].sum()
print("\nRevenue by Product:")
print(revenue_by_product.sort_values(ascending=False))
# Display overall totals
print(f"\nTotal Revenue: ${df['Revenue'].sum():,.2f}")
print(f"Total Rows: {len(df)}")
What does this code do?
- df.groupby("Product") groups all rows that share the same Product value into separate buckets.
- ["Revenue"].sum() adds up the Revenue column within each group, giving you one total per product.
- .sort_values(ascending=False) orders the results from highest to lowest revenue so you can spot the top earner immediately.
- The f-string :,.2f formats the total as a dollar amount with comma separators and two decimal places.
- Save analyze_sales.py.
Before you run the script, which product do you think generates the most revenue based on the data you explored earlier?
- Run your script by entering this command in the terminal:
python analyze_sales.py
After the exploration output from earlier, you should see a new --- Revenue Analysis --- section. Laptop appears at the top of the revenue list, and the bottom shows a total revenue figure and Total Rows: 34.
Seeing a SyntaxError or NameError?
- Check that the new code is at the bottom of your file, after the df.describe() block. Placing it above the line that creates df will cause a NameError.
- Make sure the f-string lines use the exact quote marks and curly braces shown above. A missing f before the opening quote will print the literal text instead of the calculated values.
- Confirm that column names in your code match the CSV headers exactly. "Product" and "Revenue" are both capitalized.
Why is my revenue analysis printing errors instead of results?
✔️ Awesome, I've got everything!
Great. Double check you've saved analyze_sales.py.
ⓧ I'd like to double check the full code
Here is the full analyze_sales.py file so far. Compare it with yours and make sure everything matches.
import pandas as pd
df = pd.read_csv("sales_data.csv")
print("First 10 rows:")
print(df.head(10))
print("\nDataset info:")
df.info()
print("\nBasic statistics:")
print(df.describe())
print("\n--- Revenue Analysis ---")
revenue_by_product = df.groupby("Product")["Revenue"].sum()
print("\nRevenue by Product:")
print(revenue_by_product.sort_values(ascending=False))
print(f"\nTotal Revenue: ${df['Revenue'].sum():,.2f}")
print(f"Total Rows: {len(df)}")
You've answered your first business question: Laptop is the top revenue product. Next, you'll take a closer look at the dataset to check whether these numbers can actually be trusted.
Clean the Data
Your revenue analysis from the last step produced clean-looking numbers. Laptop topped the chart and the total revenue came out to a tidy figure. But those numbers are wrong.
The dataset contains 4 duplicate Laptop rows that inflate Laptop revenue by $14,400. It also has missing values that cause a Monitor transaction to be silently excluded from your totals. Real-world data is almost always dirty, and running analysis on uncleaned data produces misleading results.
In this step, get ready to:
- Find and remove duplicate rows from the dataset.
- Fill in missing values for the Revenue and Units columns.
- Re-run the revenue analysis on the cleaned data and compare the results.
Find and remove duplicate rows
The last four rows of your CSV are exact copies of earlier Laptop transactions. These duplicates quietly inflated your Laptop revenue by $14,400.
- In analyze_sales.py, add the following code at the bottom of the file, below the Total Rows print line:
# Clean the data
print("\n--- Cleaning ---")
print(f"Duplicate rows found: {df.duplicated().sum()}")
df = df.drop_duplicates()
print(f"Rows after removing duplicates: {len(df)}")
What does this code do?
- df.duplicated().sum() checks every row against all other rows and counts the exact matches.
- df.drop_duplicates() removes those duplicate rows, keeping only the first occurrence of each.
- The result is reassigned back to df, so the rest of your script works with the cleaned data from this point forward.
- Save analyze_sales.py.
- Run the script in your terminal:
python analyze_sales.py
Scroll down to the --- Cleaning --- section. You should see Duplicate rows found: 4 and Rows after removing duplicates: 30.
Seeing 0 duplicates?
- Make sure your sales_data.csv has all 34 rows, including the 4 duplicate Laptop rows at the very bottom of the file.
- Check that the new code is placed after the existing Revenue Analysis code, not before it.
- Why is my duplicate count showing 0 instead of 4?
Find and fill missing values
Duplicates are gone, but there is another data quality issue lurking. Three rows are missing a Units value, and one row is missing a Revenue value.
Why do missing values matter?
pandas skips missing values during calculations by default. That means the Monitor transaction with no Revenue value was silently excluded from your totals in the previous step. You never got an error. The number just came out wrong.
- Add the following code below the duplicate removal code in analyze_sales.py:
print(f"\nMissing values:\n{df.isnull().sum()}")
df["Revenue"] = df["Revenue"].fillna(df["Revenue"].median())
df["Units"] = df["Units"].fillna(0)
What does this code do?
- df.isnull().sum() counts how many missing values exist in each column so you can see the scope of the problem.
- fillna(df["Revenue"].median()) replaces the missing Revenue value with the median (middle value) of all existing Revenue values. The median is a common choice because it is not skewed by extreme values the way an average would be.
- fillna(0) fills missing Units with 0, since there is no way to know how many units were actually sold in those transactions.
- Save analyze_sales.py.
Re-run the analysis on clean data
With duplicates removed and missing values filled, it is time to re-run the same revenue calculation. The before and after numbers will both print in the same terminal output so you can compare them directly.
- Add the following code to the bottom of analyze_sales.py:
# Re-analyze with clean data
print("\n--- After Cleaning ---")
revenue_by_product = df.groupby("Product")["Revenue"].sum()
print("\nRevenue by Product (cleaned):")
print(revenue_by_product.sort_values(ascending=False))
print(f"\nTotal Revenue: ${df['Revenue'].sum():,.2f}")
print(f"Total Rows: {len(df)}")
What does this code do?
- This is the same groupby and sum calculation from your earlier Revenue Analysis section, but now it runs on the cleaned DataFrame with 30 rows instead of 34.
- Both the original "Revenue Analysis" section (dirty data) and this "After Cleaning" section print in the same terminal output, so you can compare them side by side.
Before you run this, think about what you expect to happen. Will the total revenue go up or down after removing those 4 duplicate Laptop rows and filling in missing values?
- Save analyze_sales.py.
- Run the script by entering this command in your terminal:
python analyze_sales.py
The total revenue drops. Those 4 duplicate Laptop rows added $14,400 in fake revenue, and now the totals reflect the real data. The row count drops from 34 to 30.
Why is this moment important?
You just experienced exactly what happens in real data work. The original numbers looked perfectly reasonable. Nothing was obviously broken. But the analysis was silently wrong because of dirty data. This is why data cleaning is the first step in every professional analysis pipeline.
✔️ Awesome, I've got everything!
Great. Double check you have saved analyze_sales.py before moving on.
ⓧ I'd like to double check the full code
Your analyze_sales.py file should now have these sections in order. Scroll up through your file and confirm each one is present.
- The import pandas as pd import and pd.read_csv("sales_data.csv") line from Step 2.
- The exploration prints: head(10), df.info(), and df.describe() from Step 2.
- The "--- Revenue Analysis ---" section with groupby, total revenue, and row count from Step 3.
- The "--- Cleaning ---" section with drop_duplicates() from this step.
- The missing values section with fillna() calls for Revenue and Units from this step.
- The "--- After Cleaning ---" section with the re-calculated revenue_by_product and totals from this step.
Before and after numbers look the same?
- Make sure the cleaning code (drop_duplicates() and fillna()) is placed between the original Revenue Analysis section and the After Cleaning section. The order matters because df must be modified before the second calculation runs.
- Check that you reassigned the result back to df with df = df.drop_duplicates(). Writing df.drop_duplicates() without the df = does not change the original DataFrame.
- Why are my before and after revenue numbers the same?
Your data is clean and your revenue numbers are accurate. Next up, you'll turn those numbers into professional charts that tell the story visually.
Visualize Your Insights
In the previous step, you cleaned your dataset and watched the revenue totals drop to their true values. Your terminal output now tells an accurate story.
Numbers in a terminal are great for you, but hard to share with someone who was not sitting beside you. In this step, you will turn those cleaned numbers into two professional charts using matplotlib and save them as PNG files that anyone can open and understand at a glance.
In this step, get ready to:
- Create a horizontal bar chart showing revenue by product.
- Create a line chart showing the monthly revenue trend.
Create a bar chart of revenue by product
Charts are how data scientists present findings in the real world. A bar chart is one of the most effective ways to compare values across categories, like seeing which product generates the most revenue.
- In analyze_sales.py, find the line import pandas as pd at the very top of the file.
- Add this new import directly below it:
import matplotlib.pyplot as plt
- Scroll to the very bottom of analyze_sales.py and add the following code to create your bar chart:
# Visualize: Bar chart - Revenue by Product
fig, ax = plt.subplots(figsize=(10, 6))
revenue_by_product.sort_values().plot(kind="barh", ax=ax, color="steelblue")
ax.set_xlabel("Revenue ($)")
ax.set_ylabel("Product")
ax.set_title("Revenue by Product")
plt.tight_layout()
plt.savefig("revenue_by_product.png")
plt.show()
What does this code do?
- plt.subplots(figsize=(10, 6)) creates a blank figure that is 10 inches wide and 6 inches tall.
- revenue_by_product.sort_values().plot(kind="barh") plots the data as horizontal bars, sorted from smallest at the top to largest at the bottom.
- plt.savefig("revenue_by_product.png") saves the chart as a PNG image file in your project folder before showing it on screen.
- plt.show() opens the chart in a popup window. The script pauses until you close this window.
- Save analyze_sales.py.
- Run the script by entering this command in the terminal:
python analyze_sales.py
After the familiar terminal output scrolls past, a chart window pops up showing a horizontal bar chart with products on the y-axis and revenue on the x-axis. Laptop sits at the bottom with the longest bar.
- Close the chart window to let the script finish.
Don't see a chart window?
- Make sure you added import matplotlib.pyplot as plt at the top of the file, right below import pandas as pd.
- Check that the chart code is at the very bottom of the file, after the cleaning section.
- If the chart window appears behind your VS Code window, check your taskbar or dock for it.
Why isn't my matplotlib chart showing up?
Create a line chart of monthly revenue
The bar chart answers "which product makes the most money?" but a business also needs to know how revenue changes over time. A line chart is the standard way to show trends across months.
- Add the following code at the very bottom of analyze_sales.py, below the bar chart code you just added:
# Visualize: Line chart - Monthly Revenue Trend
df["Date"] = pd.to_datetime(df["Date"])
df["Month"] = df["Date"].dt.strftime("%Y-%m")
monthly_revenue = df.groupby("Month")["Revenue"].sum()
fig, ax = plt.subplots(figsize=(10, 6))
monthly_revenue.plot(kind="line", ax=ax, marker="o", color="steelblue")
ax.set_xlabel("Month")
ax.set_ylabel("Revenue ($)")
ax.set_title("Monthly Revenue Trend")
plt.tight_layout()
plt.savefig("monthly_revenue.png")
plt.show()
What does this code do?
- pd.to_datetime(df["Date"]) converts the Date column from plain text strings into proper date objects that Python can sort and group correctly.
- .dt.strftime("%Y-%m") extracts just the year and month portion (like 2024-01) so all transactions within the same month get grouped together.
- marker="o" adds a circle dot at each data point on the line, making it easy to see exactly which months have data.
- Save analyze_sales.py.
Before you run the script, how many chart windows do you think will pop up this time?
- Run the script again by entering this command:
python analyze_sales.py
Two chart windows pop up one after the other. The bar chart from earlier appears first. Close it, and the line chart appears showing the monthly revenue trend from January to December 2024 with circle markers at each data point.
- Close the line chart window to let the script finish.
- Confirm that both PNG files were saved by running:
ls
You should see revenue_by_product.png and monthly_revenue.png listed alongside analyze_sales.py and sales_data.csv.
Don't see the PNG files?
- Make sure you have plt.savefig() called before plt.show() in both chart sections. If savefig comes after show, the figure is already cleared and you get a blank PNG.
- Check that your terminal is in the sales-analysis folder. The PNGs save to whatever directory the terminal is currently in.
Why aren't my matplotlib charts saving as PNG files?
✔️ Awesome, I've got everything!
Great. Double check you have saved analyze_sales.py and both PNG files are showing in your folder.
ⓧ I'd like to double check the full code
Your analyze_sales.py file is now quite long. Scroll through and confirm these sections are present, in this order:
- Two imports at the top: import pandas as pd and import matplotlib.pyplot as plt.
- Data loading and exploration section (read_csv, head, info, describe).
- Initial revenue analysis section (the "Revenue Analysis" print block).
- Cleaning section (drop_duplicates, fillna).
- "After Cleaning" re-analysis section.
- Bar chart section (kind="barh", saves to revenue_by_product.png).
- Line chart section (kind="line", saves to monthly_revenue.png).
Secret mission
Regional Revenue Breakdown
Your analysis covers products and months, but stakeholders also want to know which regions drive the most revenue. Extend your script to build a regional breakdown with a grouped bar chart that compares products across all four regions.
Clean Up Your Resources
Clean Up Your Resources
Decide whether to keep your resources running, pause them to come back later, or delete them entirely. This project runs entirely locally, so there are no ongoing costs.
Resources you used:
- The sales-analysis project folder on your Desktop, containing your Python script, CSV files, and PNG chart images.
- The pandas and matplotlib Python libraries installed via pip.
Keep everything running
No action needed. Choose this if you're still actively building or want to experiment with the dataset and charts further.
- Your sales-analysis folder stays on your Desktop with all scripts, data files, and chart images intact.
- The pandas and matplotlib libraries remain installed and available for future Python projects.
Pause - I'll come back to this later
Close your project to free up system resources. Your files and libraries stay in place for when you return.
- Close the sales-analysis folder in VS Code by clicking File, then Close Folder.
- When you're ready to return, reopen the sales-analysis folder from your Desktop in VS Code.
Delete - I don't want to use this again
Remove all project files and optionally uninstall the Python libraries you added.
- Close the sales-analysis folder in VS Code by clicking File, then Close Folder.
- Delete the project folder by running this command in your terminal:
macOS
rm -rf ~/Desktop/sales-analysis
Windows
rmdir /s /q %USERPROFILE%\Desktop\sales-analysis
- Uninstall the Python libraries by running:
pip uninstall pandas matplotlib -y
Nice Work!
Nice Work!
You just built a Python script that takes a messy sales dataset, cleans it, crunches the numbers, and produces professional charts. That is the core data analysis workflow that pandas and matplotlib power across thousands of analyst roles every day.
You've learned how to:
- Load, explore, and analyze a CSV dataset using .head(), .info(), .describe(), and .groupby() to answer the question "which product makes the most money?".
- Catch and fix data quality issues that silently corrupt results. Four duplicate rows inflated Laptop revenue by $14,400, and missing values excluded a Monitor transaction entirely. You removed them with .drop_duplicates() and .fillna().
- Create professional visualizations with matplotlib. Your horizontal bar chart and line chart turn cleaned data into a visual story, saved as reusable PNG files.
- Secret Mission: Built a regional revenue breakdown with a grouped bar chart comparing products across regions, and exported the cleaned dataset to a new CSV.
Ready to quiz yourself?