-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_t2.py
328 lines (246 loc) · 9.46 KB
/
project_t2.py
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.backends.backend_pdf import PdfPages
import warnings
warnings.filterwarnings('ignore')
order=pd.read_csv("orders_2016-2020_Dataset.csv")
review=pd.read_csv("review_dataset.csv")
# 1. Analysis of Reviews given by Customers
def visualize_review_data():
# # Check for missing values and replace with "Not reviewed"
# review.fillna('Not reviewed', inplace=True)
# Count the number of reviews for each star rating
stars_count = review['stars'].value_counts()
# Create a pie chart of star ratings
plt.figure(figsize=(8, 6))
stars_count[0:4].plot(kind='pie', autopct='%1.1f%%', startangle=0)
plt.title('Star Ratings for Reviews')
plt.axis('equal')
# Save the plot as a PDF file
with PdfPages('1.pdf') as pdf:
pdf.savefig()
# Save the star count as an Excel file
stars_count.to_excel('1.xlsx')
# visualize_review_data()
# 2. Analysis of different payment methods used by the Customers
order[['method','amount']]=order['Payment Method'].str.split('₹',1,expand=True)
order.method.unique()
def visualize_payment_data():
order[['method', 'amount']] = order['Payment Method'].str.split('₹', 1, expand=True)
order.method.unique()
method_count = order.method.value_counts()
# Create bar plot of payment method counts
plt.figure(figsize=(20, 7))
# sns.barplot(x=method_count.index, y=method_count.values)
method_count.plot(kind='pie', autopct='%1.1f%%')
plt.title("Payment Method Counts")
# Save the plot as a PDF file
with PdfPages('2.pdf') as pdf:
pdf.savefig()
# Excel
method_count.to_excel('2.xlsx')
# visualize_payment_data()
# 3. Analysis of Top Consumer States of India
def visualize_top_state():
state_count = order['Shipping State'].value_counts()
# Create bar plot of payment method counts
plt.figure(figsize=(20, 7))
# sns.barplot(x=method_count.index, y=method_count.values)
state_count[0:5].plot(kind='pie', autopct='%1.1f%%')
plt.title("Top Consumer States of India")
# Save the plot as a PDF file
with PdfPages('3.pdf') as pdf:
pdf.savefig()
# Excel file
state_count.to_excel('3.xlsx')
# visualize_top_state()
# 4. Analysis of Top Consumer Cities of India
city_count = order['Shipping City'].value_counts()
def visualize_top_city():
city_count = order['Shipping City'].value_counts()
# Create bar plot of payment method counts
plt.figure(figsize=(20, 7))
# sns.barplot(x=method_count.index, y=method_count.values)
city_count[0:5].plot(kind='pie', autopct='%1.1f%%')
plt.title("Top Consumer Cities of India")
# Save the plot as a PDF file
with PdfPages('4.pdf') as pdf:
pdf.savefig()
# Excel file
city_count.to_excel('4.xlsx')
# visualize_top_city()
# 5. Analysis of Top Selling Product Categories
def visualize_top_categories():
# Group orders by product category and get count of orders for each category
category_counts = review.groupby('category')['stars'].nunique()
# Sort categories by order count and get top 10
top_categories = category_counts.sort_values(ascending=False).head(10)
# Create horizontal bar plot of top categories
plt.figure(figsize=(8, 6))
sns.barplot(x=top_categories.values, y=top_categories.index)
plt.title("Top 10 Selling Product Categories")
plt.xlabel("Number of Orders")
plt.ylabel("Product Category")
# Save the plot as a PDF file
with PdfPages('5.pdf') as pdf:
pdf.savefig()
# Excel file
top_categories.to_excel('5.xlsx')
# visualize_top_categories()
# 6. Analysis of Reviews for All Product Categories
status=review['status']
status.fillna('not reviewed',inplace=True)
status.value_counts()
def reviews_all_category():
status = review['status']
status.fillna('not reviewed', inplace=True)
status_count = status.value_counts()
# Create bar plot of payment method counts
plt.figure(figsize=(20, 7))
status_count.plot(kind='pie', autopct='%1.1f%%')
plt.title("Reviews for All Categories")
# Save the plot as a PDF file
with PdfPages('6.pdf') as pdf:
pdf.savefig()
# Excel file
status_count.to_excel('6.xlsx')
# reviews_all_category()
# 7. Analysis of Number of Orders Per Month Per Year
date=order[order['Fulfillment Status']=='Fulfilled']
date['Fulfillment Date and Time Stamp']=pd.to_datetime(date['Fulfillment Date and Time Stamp'])
date['month']=date['Fulfillment Date and Time Stamp'].dt.strftime('%B')
date['year']=date['Fulfillment Date and Time Stamp'].dt.strftime('%Y')
date['month'].value_counts()
date['year'].value_counts()
date.head()
def order_per_month_year():
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 8))
month_count = date['month'].value_counts()
year_count = date['year'].value_counts()
# Plot pie chart for distribution of months
month_count.plot(kind='pie', autopct='%1.1f%%', ax=ax1)
ax1.set_title('orders per month')
# Plot pie chart for distribution of years
year_count.plot(kind='pie', autopct='%1.1f%%', ax=ax2)
ax2.set_title('orders per year')
# Save the plot as a PDF file
with PdfPages('7.pdf') as pdf:
pdf.savefig()
# Excel file
month_count.to_excel('7-1.xlsx')
year_count.to_excel('7-2.xlsx')
# order_per_month_year()
# 8. analysis of Reviews for Number of Orders Per Month Per Year
df1=order
df2=review
df1.rename(columns={'LineItem Name':'product_name'},inplace=True)
merge=pd.merge(df1,df2,on='product_name')
merge['Fulfillment Date and Time Stamp']=pd.to_datetime(merge['Fulfillment Date and Time Stamp'])
merge['month']=merge['Fulfillment Date and Time Stamp'].dt.strftime('%B')
merge['year']=merge['Fulfillment Date and Time Stamp'].dt.strftime('%Y')
merge.head()
month_counts = merge.groupby('month')['stars'].value_counts()
year_counts = merge.groupby('year')['stars'].value_counts()
def reviews_order_per_month_year():
month_counts = merge.groupby('month')['stars'].value_counts()
year_counts = merge.groupby('year')['stars'].value_counts()
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 12))
# Plot pie chart for distribution of months
month_counts[:4].plot(kind='pie', autopct='%1.1f%%', ax=ax1)
ax1.set_title('reviews of orders per month')
# Plot pie chart for distribution of years
year_counts[:6].plot(kind='pie', autopct='%1.1f%%', ax=ax2)
ax2.set_title(' reviews of orders per year')
# Save the plot as a PDF file
with PdfPages('8.pdf') as pdf:
pdf.savefig()
# Excel file
month_counts.to_excel('8-1.xlsx')
year_counts.to_excel('8-2.xlsx')
# reviews_order_per_month_year()
# 9. analysis of Number of Orders Across Parts of a Day
date['hour']=date['Fulfillment Date and Time Stamp'].dt.strftime('%H')
def order_per_parts_of_day():
hour_count = date.hour.value_counts()
# Create bar plot of payment method counts
plt.figure(figsize=(20, 7))
hour_count[:10].plot(kind='pie', autopct='%1.1f%%')
plt.title("order per parts of day")
# Save the plot as a PDF file
with PdfPages('9.pdf') as pdf:
pdf.savefig()
# Excel file
hour_count.to_excel('9.xlsx')
# order_per_parts_of_day()
# 10.Full report
def all_report():
with PdfPages('report.pdf') as pdf_output:
# Visualize Review Data
plt.figure(figsize=(8, 6))
visualize_review_data()
pdf_output.savefig()
# plt.close()
# Visualize Payment Data
plt.figure(figsize=(8, 6))
visualize_payment_data()
pdf_output.savefig()
# plt.close()
# Visualize Top State
plt.figure(figsize=(8, 6))
visualize_top_state()
pdf_output.savefig()
# plt.close()
# Visualize Top City
plt.figure(figsize=(8, 6))
visualize_top_city()
pdf_output.savefig()
# plt.close()
# Visualize Top Categories
plt.figure(figsize=(8, 6))
visualize_top_categories()
pdf_output.savefig()
# plt.close()
# Visualize reviews all category
plt.figure(figsize=(8, 6))
reviews_all_category()
pdf_output.savefig()
# plt.close()
# Visualize order per month and year
plt.figure(figsize=(8, 6))
order_per_month_year()
pdf_output.savefig()
# plt.close()
# Visualize reviews of order per month and year
plt.figure(figsize=(8, 6))
reviews_order_per_month_year()
pdf_output.savefig()
# plt.close()
# Visualize order per part of day
plt.figure(figsize=(8, 6))
order_per_parts_of_day()
pdf_output.savefig()
# plt.close()
# all_report()
a=int(input('Enter the value: '))
if a==1:
visualize_review_data()
elif a==2:
visualize_payment_data()
elif a==3:
visualize_top_state()
elif a==4:
visualize_top_city()
elif a==5:
visualize_top_categories()
elif a==6:
reviews_all_category()
elif a==7:
order_per_month_year()
elif a==8:
reviews_order_per_month_year()
elif a==9:
order_per_parts_of_day()
else:
all_report()