Chitranshu commited on
Commit
9097e3c
1 Parent(s): 9558078

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +162 -0
app.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import panel as pn
4
+ pn.extension('tabulator')
5
+
6
+ import hvplot.pandas
7
+
8
+ project_data = pd.read_csv(r'DMart.csv')
9
+ project_data.columns
10
+ project_data.info()
11
+ project_data.describe()
12
+ project_data.isna().sum()
13
+ project_data.shape
14
+ project_data['Brand'] = project_data['Brand'].fillna('others')
15
+ project_data.isna().sum()
16
+ project_data = project_data.dropna()
17
+ project_data.isna().sum()
18
+ df = pd.DataFrame(project_data)
19
+ idf = df.interactive()
20
+ df.groupby(by=["SubCategory","Quantity"], dropna=False, sort=True).sum()
21
+ import pandas as pd
22
+ import panel as pn
23
+ import hvplot.pandas
24
+ import seaborn as sns
25
+ import pandas as pd
26
+ import seaborn as sns
27
+ import hvplot.pandas
28
+ import panel as pn
29
+
30
+ # Assuming your dataset is stored in a DataFrame called 'df'
31
+
32
+ # Create an interactive DataFrame
33
+ idf = df.interactive()
34
+
35
+ # Define Panel widgets for Top 10 Brands and Top 10 Categories
36
+ brand_count = df['Brand'].value_counts().nlargest(10)
37
+ category_count = df['Category'].value_counts().nlargest(10)
38
+
39
+ # Define the hvplot charts with increased size
40
+ brand_chart = brand_count.hvplot.bar(rot=90, title='Top 10 Brands', color=['#206b33'], width=800, height=400) # Different shades of green
41
+ category_chart = category_count.hvplot.bar(rot=90, title='Top 10 Categories', color=['#206b33'], width=800, height=400)
42
+
43
+ # Create brand_price and category_price dictionaries
44
+ brand_price = {}
45
+ category_price = {}
46
+
47
+ def brand_and_top_price():
48
+ for index, row in project_data.iterrows():
49
+ if row["Brand"] in brand_price:
50
+ if brand_price.get(row["Brand"]) < row["Price"]:
51
+ brand_price[row["Brand"]] = row["Price"]
52
+ else:
53
+ brand_price[row["Brand"]] = row["Price"]
54
+
55
+ def category_and_top_price():
56
+ for index, row in project_data.iterrows():
57
+ if row["Category"] in category_price:
58
+ if category_price.get(row["Category"]) < row["Price"]:
59
+ category_price[row["Category"]] = row["Price"]
60
+ else:
61
+ category_price[row["Category"]] = row["Price"]
62
+
63
+ brand_and_top_price()
64
+ category_and_top_price()
65
+ project_data_interactive = project_data.interactive()
66
+ idf = df.interactive()
67
+
68
+ # Define Panel widgets
69
+ category_1 = project_data['Category'].value_counts().nlargest(10)
70
+ brand_1 = project_data["Brand"].value_counts().nlargest(15).sort_values(ascending=False)
71
+ # Define the hvplot charts
72
+ category_chart = category_1.hvplot.bar(rot=90, title='Category Distribution', color=['#206b33'], width=800, height=400)
73
+ brand_chart = brand_1.hvplot.bar(rot=90, title='Brand Count Distribution (Top 15)', color=['#206b33'], width=800, height=400)
74
+ price_chart = df.hvplot.kde(y='Price', color='#006400', width=800, height=400)
75
+ discounted_price_chart = df.hvplot.kde(y='DiscountedPrice', color='#006400', width=800, height=400)
76
+ brand_price = dict(sorted(brand_price.items(), key=lambda item: item[1], reverse=True))
77
+ category_price = dict(sorted(category_price.items(), key=lambda item: item[1], reverse=True))
78
+
79
+ df_brand = pd.DataFrame(brand_price.items(), columns=['Brand', 'Price']).head(20)
80
+ df_category = pd.DataFrame(category_price.items(), columns=['Category', 'Price']).head(20)
81
+
82
+ # Create a reversed green color palette
83
+ green_palette = sns.color_palette('Greens', n_colors=20)
84
+ reversed_palette = list(reversed(green_palette))
85
+
86
+ # Create brand bar chart using hvPlot
87
+ brand_price_chart = df_brand.hvplot.bar(x='Brand', y='Price', rot=90, color=reversed_palette,
88
+ title='Top Price in Every Brand', xlabel='Brand', ylabel='Price',
89
+ width=800, height=400)
90
+
91
+ # Create category bar chart using hvPlot
92
+ category_price_chart = df_category.hvplot.bar(x='Category', y='Price', rot=90, color=green_palette[::-1],
93
+ title='Top Price in Every Category', xlabel='Category', ylabel='Price',
94
+ width=800, height=400)
95
+
96
+ # Define Panel widgets
97
+ yaxis_radio = pn.widgets.RadioButtonGroup(
98
+ name='Y axis',
99
+ options=['Top 10 Brands', 'Top 10 Categories', 'Top Price Brands', 'Top Price Categories', 'Category Distribution', 'Brand Count Distribution', 'Price', 'DiscountedPrice'],
100
+ button_type='success',
101
+ inline=True
102
+ )
103
+
104
+ # Define the Panel layout
105
+ panel_layout = pn.Column(
106
+ yaxis_radio
107
+ )
108
+
109
+ # Define the callback function for the radio button
110
+ def update_chart(event):
111
+ if event.new == 'Top 10 Brands':
112
+ panel_layout[1:] = [brand_chart]
113
+ elif event.new == 'Top 10 Categories':
114
+ panel_layout[1:] = [category_chart]
115
+ elif event.new == 'Top Price Brands':
116
+ panel_layout[1:] = [brand_price_chart]
117
+ elif event.new == 'Top Price Categories':
118
+ panel_layout[1:] = [category_price_chart]
119
+ elif event.new == 'Category Distribution':
120
+ panel_layout[1:] = [category_chart]
121
+ elif event.new == 'Brand Count Distribution':
122
+ panel_layout[1:] = [brand_chart]
123
+ elif event.new == 'Price':
124
+ panel_layout[1:] = [price_chart]
125
+ elif event.new == 'DiscountedPrice':
126
+ panel_layout[1:] = [discounted_price_chart]
127
+
128
+ yaxis_radio.param.watch(update_chart, 'value')
129
+
130
+ # Display the initial chart
131
+ panel_layout.append(brand_chart)
132
+
133
+ # Display the Panel layout
134
+ panel_layout
135
+ dashboard = panel_layout
136
+ import panel as pn
137
+ pn.extension() # Add this line to load the Panel extension
138
+
139
+ # Layout using Template
140
+ template = pn.template.FastListTemplate(
141
+ title='D-mart Products Analysis Dashboard',
142
+ sidebar=[
143
+ pn.pane.PNG('Dmart.png', sizing_mode='scale_both'),
144
+ pn.pane.Markdown("# Key Performance Indicators (KPIs) of the EDA"),
145
+ pn.pane.Markdown("1. Count of Brands: The count of each brand, indicating brand popularity or representation in the dataset."),
146
+ pn.pane.Markdown("2. Count of Prices: The count of different price values, providing insights into price distribution."),
147
+ pn.pane.Markdown("3. Count of Categories: The count of each category, helping understand the distribution of products across categories."),
148
+ pn.pane.Markdown("4. Price Distribution: The density plot shows the distribution of prices, allowing analysis of price ranges and outliers."),
149
+ pn.pane.Markdown("5. Top Price in Every Brand: Identifies the brands with the highest prices, indicating premium or luxury brands."),
150
+ pn.pane.Markdown("6. Top Price in Every Category: Shows the categories with the highest prices, providing insights into expensive product categories."),
151
+ pn.pane.Markdown("7. Grouping and Summarizing: Summarizes the data by grouping based on 'SubCategory' and 'Quantity,' enabling analysis of aggregated metrics."),
152
+ pn.pane.Markdown("8. Price Distribution (Discounted vs. Original): Compares the distributions of discounted and original prices, offering insights into pricing strategies and discounts.")
153
+ ],
154
+ main = [pn.Row(pn.Column(dashboard)),
155
+ pn.Row(pn.pane.Markdown("DMart is a one-stop supermarket chain that aims to offer customers a wide range of basic home and personal products under one roof. Each DMart store stocks home utility products - including food, toiletries, beauty products, garments, kitchenware, bed and bath linen, home appliances and more - available at competitive prices that our customers appreciate. Our core objective is to offer customers good products at great value.DMart was started by Mr. Radhakishan Damani and his family to address the growing needs of the Indian family. From the launch of its first store in Powai in 2002, DMart today has a well-established presence in 327 locations across India. With D-marts mission is to be the lowest priced retailer in the regions we operate, our business continues to grow with new locations planned in more cities.The supermarket chain of DMart stores is owned and operated by Avenue Supermarts Ltd. (ASL). The company has its headquarters in Mumbai.The brands D Mart, D Mart Minimax, D Mart Premia, D Homes, Dutch Harbour, etc are brands owned by ASL.")),
156
+ pn.Row(pn.pane.Markdown("Designed and Developed with ❤️ by Chitranshu Nagdawane © 2023"))
157
+ ],
158
+ accent_base_color="#206b33",
159
+ header_background="#206b33"
160
+ )
161
+
162
+ template.servable()