-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
112 lines (74 loc) · 1.84 KB
/
Copy pathanalysis.py
File metadata and controls
112 lines (74 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import pandas as pd
df = pd.read_csv("Superstore.csv", encoding="latin1")
print("Total Sales:")
print(df["Sales"].sum())
print("\nTotal Profit:")
print(df["Profit"].sum())
print("\nAverage Sales:")
print(df["Sales"].mean())
print("\nAverage Profit:")
print(df["Profit"].mean())
category_sales = df.groupby("Category")["Sales"].sum()
print("\nCategory Wise Sales:")
print(category_sales)
category_profit = df.groupby("Category")["Profit"].sum()
print("\nCategory Wise Profit:")
print(category_profit)
top_products = df.groupby(
"Product Name"
)["Sales"].sum()
print("\nTop 10 Products")
print(
top_products.sort_values(
ascending=False
).head(10)
)
print(df.columns)
import matplotlib.pyplot as plt
category_sales.plot(kind="bar")
plt.title("Category Wise Sales")
plt.xlabel("Category")
plt.ylabel("Sales")
plt.savefig("images/category_sales.png")
plt.show()
plt.figure()
category_profit.plot(kind="bar")
plt.title("Category Wise Profit")
plt.xlabel("Category")
plt.ylabel("Profit")
plt.savefig("images/profit_analysis.png")
plt.show()
plt.figure(figsize=(10,5))
top_products.sort_values(
ascending=False
).head(10).plot(kind="bar")
plt.title("Top 10 Products")
plt.xlabel("Products")
plt.ylabel("Sales")
plt.savefig("images/top_products.png")
plt.show()
df["Order Date"] = pd.to_datetime(df["Order Date"])
df["Month"] = df["Order Date"].dt.to_period("M")
monthly_sales = df.groupby(
"Month"
)["Sales"].sum()
plt.figure(figsize=(12,5))
monthly_sales.plot(
kind="line",
marker="o"
)
plt.title("Monthly Sales Trend")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.savefig("images/monthly_sales_trend.png")
plt.show()
plt.figure(figsize=(8,5))
plt.scatter(
df["Sales"],
df["Profit"]
)
plt.title("Sales vs Profit")
plt.xlabel("Sales")
plt.ylabel("Profit")
plt.savefig("images/sales_vs_profit.png")
plt.show()