0% found this document useful (0 votes)
4 views4 pages

Python ASSIGNMENT Thursday

The document contains a Python assignment that involves analyzing sales data for jewelry products using pandas and matplotlib. It includes code to create a DataFrame, calculate total sales, and generate bar and line graphs for sales by product, category, and date. The output consists of three graphs visualizing the sales data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Python ASSIGNMENT Thursday

The document contains a Python assignment that involves analyzing sales data for jewelry products using pandas and matplotlib. It includes code to create a DataFrame, calculate total sales, and generate bar and line graphs for sales by product, category, and date. The output consists of three graphs visualizing the sales data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Assignment

Code :
import pandas as pd
import matplotlib.pyplot as plt
data = {
'Product':
['Necklace','Bangles','Ring','Pendant','Necklace','Bangles','Ring','Necklace'],
'Category':
['Jwellery','Jwellery','Jwellery','Jwellery','Jwellery','Jwellery','Jwellery','Jwellery'
],
'Quantity Sold': [30, 45, 60, 95, 50, 20, 70, 65],
'Unit Price': [55000, 45000, 12000, 25000, 55000, 45000, 12000, 55000],
'Date': pd.to_datetime(['2024-12-11', '2024-12-11', '2024-12-11', '2024-12-11',
'2025-01-12', '2025-01-12', '2025-01-12', '2025-01-12'])
}
df = pd.DataFrame(data)
df['Total Sales'] = df['Quantity Sold'] * df['Unit Price']
print("Sales Data Table:")
print(df)
sales_by_product = df.groupby('Product')['Total
Sales'].sum().sort_values(ascending=False)
sales_by_category = df.groupby('Category')['Total Sales'].sum()
sales_by_date = df.groupby('Date')['Total Sales'].sum()
print("\nTotal Sales by Product:")
print(sales_by_product)
print("\nTotal Sales by Category:")
print(sales_by_category)
print("\nTotal Sales by Date:")
print(sales_by_date)
plt.figure(figsize=(8, 6))
sales_by_product.plot(kind='bar', color='skyblue')
plt.title('Total Sales by Product')
plt.xlabel('Product')
plt.ylabel('Total Sales ($)')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
plt.figure(figsize=(8, 6))
sales_by_category.plot(kind='bar', color='salmon')
plt.title('Total Sales by Category')
plt.xlabel('Category')
plt.ylabel('Total Sales ($)')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
plt.figure(figsize=(8, 6))
sales_by_date.plot(kind='line', marker='o', color='green')
plt.title('Total Sales Over Time')
plt.xlabel('Date')
plt.ylabel('Total Sales ($)')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
Output :

Graph -1
Graph -2

Graph -3

You might also like