Challenge 1: Sales Data Analysis
Test your data manipulation skills with the sales dataset in pandas and Matplotlib.
In this exercise, use the pandas and Matplotlib libraries to analyze sales data from a CSV file. You’ll perform the following tasks.
Task 1: Load the dataset
Load the data into a pandas DataFrame using the pd.read_csv
function and store it in a variable called sales_data
. The file name is Sales-Data.csv
. Display the first five rows of the data at the end.
Press + to interact
main.py
Sales-Data.csv
Date,Product,Sales,Profit,Region2023-01-01,Product_A,1500,300,North2023-01-01,Product_B,2000,500,South2023-01-02,Product_A,1600,350,East2023-01-02,Product_C,1200,200,West2023-01-03,Product_B,1800,450,North2023-01-03,Product_C,1400,250,South2023-01-04,Product_A,1700,370,East2023-01-04,Product_B,1900,480,West2023-01-05,Product_C,1300,220,North2023-01-05,Product_A,1800,400,South
Task 2: Plot the data
Create a bar plot showing total sales for each product. Use the groupby
and sum
functions from pandas to calculate the total sales.
Press + to interact
main.py
Sales-Data.csv
Date,Product,Sales,Profit,Region2023-01-01,Product_A,1500,300,North2023-01-01,Product_B,2000,500,South2023-01-02,Product_A,1600,350,East2023-01-02,Product_C,1200,200,West2023-01-03,Product_B,1800,450,North2023-01-03,Product_C,1400,250,South2023-01-04,Product_A,1700,370,East2023-01-04,Product_B,1900,480,West2023-01-05,Product_C,1300,220,North2023-01-05,Product_A,1800,400,South
Task 3: Manipulate the data
Create a new column in sales_data
called Profit Margin
that contains the calculated profit margin values using the formula: