-
Notifications
You must be signed in to change notification settings - Fork 0
/
Phonepe_Pulse_dashboard.py
395 lines (312 loc) · 23.2 KB
/
Phonepe_Pulse_dashboard.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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# ================================================== / IMPORT LIBRARY / =================================================== #
# [clone libraries]
import requests
import subprocess
# [pandas, numpy and file handling libraries]
import pandas as pd
import numpy as np
import os
import json
# [SQL libraries]
import mysql.connector
import sqlalchemy
from sqlalchemy import create_engine
import pymysql
# [Dash board libraries]
import streamlit as st
import plotly.express as px
# ============================================== / / DASHBOARD / / ================================================== #
# ============== / CONNECT SQL SERVER / ACCESS DATA BASE / EXECUTE SQL QUERIES / ACCESS DATA / ========================= #
conn = pymysql.connect(host='localhost', user='root', password='root', db='phonepe_pulse')
cursor = conn.cursor()
# ============================================ / STREAMLIT DASHBOARD / ================================================= #
# Comfiguring Streamlit GUI
st.set_page_config(layout='wide')
# Title
st.header(':violet[Phonepe Pulse Data Visualization ]')
st.write('**(Note)**:-This data between **2018** to **2022** in **INDIA**')
# Selection option
option = st.radio('**Select your option**',('All India', 'State wise','Top Ten categories'),horizontal=True)
# =================================================== / All India / ===================================================== #
if option == 'All India':
# Select tab
tab1, tab2 = st.tabs(['Transaction','User'])
# ------------------------- / All India Transaction / ------------------ #
with tab1:
col1, col2, col3 = st.columns(3)
with col1:
in_tr_yr = st.selectbox('**Select Year**', ('2018','2019','2020','2021','2022'),key='in_tr_yr')
with col2:
in_tr_qtr = st.selectbox('**Select Quarter**', ('1','2','3','4'),key='in_tr_qtr')
with col3:
in_tr_tr_typ = st.selectbox('**Select Transaction type**', ('Recharge & bill payments','Peer-to-peer payments',
'Merchant payments','Financial Services','Others'),key='in_tr_tr_typ')
# SQL Query
# Transaction Analysis bar chart query
cursor.execute(f"SELECT State, Transaction_amount FROM aggregated_transaction WHERE Year = '{in_tr_yr}' AND Quarter = '{in_tr_qtr}' AND Transaction_type = '{in_tr_tr_typ}';")
in_tr_tab_qry_rslt = cursor.fetchall()
df_in_tr_tab_qry_rslt = pd.DataFrame(np.array(in_tr_tab_qry_rslt), columns=['State', 'Transaction_amount'])
df_in_tr_tab_qry_rslt1 = df_in_tr_tab_qry_rslt.set_index(pd.Index(range(1, len(df_in_tr_tab_qry_rslt)+1)))
# Transaction Analysis table query
cursor.execute(f"SELECT State, Transaction_count, Transaction_amount FROM aggregated_transaction WHERE Year = '{in_tr_yr}' AND Quarter = '{in_tr_qtr}' AND Transaction_type = '{in_tr_tr_typ}';")
in_tr_anly_tab_qry_rslt = cursor.fetchall()
df_in_tr_anly_tab_qry_rslt = pd.DataFrame(np.array(in_tr_anly_tab_qry_rslt), columns=['State','Transaction_count','Transaction_amount'])
df_in_tr_anly_tab_qry_rslt1 = df_in_tr_anly_tab_qry_rslt.set_index(pd.Index(range(1, len(df_in_tr_anly_tab_qry_rslt)+1)))
# Total Transaction Amount table query
cursor.execute(f"SELECT SUM(Transaction_amount), AVG(Transaction_amount) FROM aggregated_transaction WHERE Year = '{in_tr_yr}' AND Quarter = '{in_tr_qtr}' AND Transaction_type = '{in_tr_tr_typ}';")
in_tr_am_qry_rslt = cursor.fetchall()
df_in_tr_am_qry_rslt = pd.DataFrame(np.array(in_tr_am_qry_rslt), columns=['Total','Average'])
df_in_tr_am_qry_rslt1 = df_in_tr_am_qry_rslt.set_index(['Average'])
# Total Transaction Count table query
cursor.execute(f"SELECT SUM(Transaction_count), AVG(Transaction_count) FROM aggregated_transaction WHERE Year = '{in_tr_yr}' AND Quarter = '{in_tr_qtr}' AND Transaction_type = '{in_tr_tr_typ}';")
in_tr_co_qry_rslt = cursor.fetchall()
df_in_tr_co_qry_rslt = pd.DataFrame(np.array(in_tr_co_qry_rslt), columns=['Total','Average'])
df_in_tr_co_qry_rslt1 = df_in_tr_co_qry_rslt.set_index(['Average'])
# --------- / Output / -------- #
# ------ / Geo visualization dashboard for Transaction / ---- #
# Drop a State column from df_in_tr_tab_qry_rslt
df_in_tr_tab_qry_rslt.drop(columns=['State'], inplace=True)
# Clone the gio data
url = "https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson"
response = requests.get(url)
data1 = json.loads(response.content)
# Extract state names and sort them in alphabetical order
state_names_tra = [feature['properties']['ST_NM'] for feature in data1['features']]
state_names_tra.sort()
# Create a DataFrame with the state names column
df_state_names_tra = pd.DataFrame({'State': state_names_tra})
# Combine the Gio State name with df_in_tr_tab_qry_rslt
df_state_names_tra['Transaction_amount']=df_in_tr_tab_qry_rslt
# convert dataframe to csv file
df_state_names_tra.to_csv('State_trans.csv', index=False)
# Read csv
df_tra = pd.read_csv('State_trans.csv')
# Geo plot
fig_tra = px.choropleth(
df_tra,
geojson="https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson",
featureidkey='properties.ST_NM',locations='State',color='Transaction_amount',color_continuous_scale='thermal',title = 'Transaction Analysis')
fig_tra.update_geos(fitbounds="locations", visible=False)
fig_tra.update_layout(title_font=dict(size=33),title_font_color='#6739b7', height=800)
st.plotly_chart(fig_tra,use_container_width=True)
# --------- / All India Transaction Analysis Bar chart / ----- #
df_in_tr_tab_qry_rslt1['State'] = df_in_tr_tab_qry_rslt1['State'].astype(str)
df_in_tr_tab_qry_rslt1['Transaction_amount'] = df_in_tr_tab_qry_rslt1['Transaction_amount'].astype(float)
df_in_tr_tab_qry_rslt1_fig = px.bar(df_in_tr_tab_qry_rslt1 , x = 'State', y ='Transaction_amount', color ='Transaction_amount', color_continuous_scale = 'thermal', title = 'Transaction Analysis Chart', height = 700,)
df_in_tr_tab_qry_rslt1_fig.update_layout(title_font=dict(size=33),title_font_color='#6739b7')
st.plotly_chart(df_in_tr_tab_qry_rslt1_fig,use_container_width=True)
# ------- / All India Total Transaction calculation Table / ---- #
st.header(':violet[Total calculation]')
col4, col5 = st.columns(2)
with col4:
st.subheader('Transaction Analysis')
st.dataframe(df_in_tr_anly_tab_qry_rslt1)
with col5:
st.subheader('Transaction Amount')
st.dataframe(df_in_tr_am_qry_rslt1)
st.subheader('Transaction Count')
st.dataframe(df_in_tr_co_qry_rslt1)
# --------------------------------------- / All India User / ------------------------------------ #
with tab2:
col1, col2 = st.columns(2)
with col1:
in_us_yr = st.selectbox('**Select Year**', ('2018','2019','2020','2021','2022'),key='in_us_yr')
with col2:
in_us_qtr = st.selectbox('**Select Quarter**', ('1','2','3','4'),key='in_us_qtr')
# SQL Query
# User Analysis Bar chart query
cursor.execute(f"SELECT State, SUM(User_Count) FROM aggregated_user WHERE Year = '{in_us_yr}' AND Quarter = '{in_us_qtr}' GROUP BY State;")
in_us_tab_qry_rslt = cursor.fetchall()
df_in_us_tab_qry_rslt = pd.DataFrame(np.array(in_us_tab_qry_rslt), columns=['State', 'User Count'])
df_in_us_tab_qry_rslt1 = df_in_us_tab_qry_rslt.set_index(pd.Index(range(1, len(df_in_us_tab_qry_rslt)+1)))
# Total User Count table query
cursor.execute(f"SELECT SUM(User_Count), AVG(User_Count) FROM aggregated_user WHERE Year = '{in_us_yr}' AND Quarter = '{in_us_qtr}';")
in_us_co_qry_rslt = cursor.fetchall()
df_in_us_co_qry_rslt = pd.DataFrame(np.array(in_us_co_qry_rslt), columns=['Total','Average'])
df_in_us_co_qry_rslt1 = df_in_us_co_qry_rslt.set_index(['Average'])
# --------- / Output / -------- #
# ------ / Geo visualization dashboard for User / ---- #
# Drop a State column from df_in_us_tab_qry_rslt
df_in_us_tab_qry_rslt.drop(columns=['State'], inplace=True)
# Clone the gio data
url = "https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson"
response = requests.get(url)
data2 = json.loads(response.content)
# Extract state names and sort them in alphabetical order
state_names_use = [feature['properties']['ST_NM'] for feature in data2['features']]
state_names_use.sort()
# Create a DataFrame with the state names column
df_state_names_use = pd.DataFrame({'State': state_names_use})
# Combine the Gio State name with df_in_tr_tab_qry_rslt
df_state_names_use['User Count']=df_in_us_tab_qry_rslt
# convert dataframe to csv file
df_state_names_use.to_csv('State_user.csv', index=False)
# Read csv
df_use = pd.read_csv('State_user.csv')
# Geo plot
fig_use = px.choropleth(
df_use,
geojson="https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson",
featureidkey='properties.ST_NM',locations='State',color='User Count',color_continuous_scale='thermal',title = 'User Analysis')
fig_use.update_geos(fitbounds="locations", visible=False)
fig_use.update_layout(title_font=dict(size=33),title_font_color='#6739b7', height=800)
st.plotly_chart(fig_use,use_container_width=True)
# ---- / All India User Analysis Bar chart / -------- #
df_in_us_tab_qry_rslt1['State'] = df_in_us_tab_qry_rslt1['State'].astype(str)
df_in_us_tab_qry_rslt1['User Count'] = df_in_us_tab_qry_rslt1['User Count'].astype(int)
df_in_us_tab_qry_rslt1_fig = px.bar(df_in_us_tab_qry_rslt1 , x = 'State', y ='User Count', color ='User Count', color_continuous_scale = 'thermal', title = 'User Analysis Chart', height = 700,)
df_in_us_tab_qry_rslt1_fig.update_layout(title_font=dict(size=33),title_font_color='#6739b7')
st.plotly_chart(df_in_us_tab_qry_rslt1_fig,use_container_width=True)
# ----- / All India Total User calculation Table / ----- #
st.header(':violet[Total calculation]')
col3, col4 = st.columns(2)
with col3:
st.subheader('User Analysis')
st.dataframe(df_in_us_tab_qry_rslt1)
with col4:
st.subheader('User Count')
st.dataframe(df_in_us_co_qry_rslt1)
# ============================================== / State wise / ============================================== #
elif option =='State wise':
# Select tab
tab3, tab4 = st.tabs(['Transaction','User'])
# --------------------------------- / State wise Transaction / ------------------------------- #
with tab3:
col1, col2,col3 = st.columns(3)
with col1:
st_tr_st = st.selectbox('**Select State**',('andaman-&-nicobar-islands', 'andhra-pradesh', 'arunachal-pradesh','assam', 'bihar',
'chandigarh', 'chhattisgarh','dadra-&-nagar-haveli-&-daman-&-diu', 'delhi', 'goa', 'gujarat', 'haryana', 'himachal-pradesh',
'jammu-&-kashmir', 'jharkhand', 'karnataka', 'kerala', 'ladakh', 'lakshadweep', 'madhya-pradesh','maharashtra', 'manipur',
'meghalaya', 'mizoram', 'nagaland','odisha', 'puducherry', 'punjab', 'rajasthan', 'sikkim', 'tamil-nadu', 'telangana',
'tripura', 'uttar-pradesh', 'uttarakhand', 'west-bengal'),key='st_tr_st')
with col2:
st_tr_yr = st.selectbox('**Select Year**', ('2018','2019','2020','2021','2022'),key='st_tr_yr')
with col3:
st_tr_qtr = st.selectbox('**Select Quarter**', ('1','2','3','4'),key='st_tr_qtr')
# SQL Query
# Transaction Analysis bar chart query
cursor.execute(f"SELECT Transaction_type, Transaction_amount FROM aggregated_transaction WHERE State = '{st_tr_st}' AND Year = '{st_tr_yr}' AND Quarter = '{st_tr_qtr}';")
st_tr_tab_bar_qry_rslt = cursor.fetchall()
df_st_tr_tab_bar_qry_rslt = pd.DataFrame(np.array(st_tr_tab_bar_qry_rslt), columns=['Transaction_type', 'Transaction_amount'])
df_st_tr_tab_bar_qry_rslt1 = df_st_tr_tab_bar_qry_rslt.set_index(pd.Index(range(1, len(df_st_tr_tab_bar_qry_rslt)+1)))
# Transaction Analysis table query
cursor.execute(f"SELECT Transaction_type, Transaction_count, Transaction_amount FROM aggregated_transaction WHERE State = '{st_tr_st}' AND Year = '{st_tr_yr}' AND Quarter = '{st_tr_qtr}';")
st_tr_anly_tab_qry_rslt = cursor.fetchall()
df_st_tr_anly_tab_qry_rslt = pd.DataFrame(np.array(st_tr_anly_tab_qry_rslt), columns=['Transaction_type','Transaction_count','Transaction_amount'])
df_st_tr_anly_tab_qry_rslt1 = df_st_tr_anly_tab_qry_rslt.set_index(pd.Index(range(1, len(df_st_tr_anly_tab_qry_rslt)+1)))
# Total Transaction Amount table query
cursor.execute(f"SELECT SUM(Transaction_amount), AVG(Transaction_amount) FROM aggregated_transaction WHERE State = '{st_tr_st}' AND Year = '{st_tr_yr}' AND Quarter = '{st_tr_qtr}';")
st_tr_am_qry_rslt = cursor.fetchall()
df_st_tr_am_qry_rslt = pd.DataFrame(np.array(st_tr_am_qry_rslt), columns=['Total','Average'])
df_st_tr_am_qry_rslt1 = df_st_tr_am_qry_rslt.set_index(['Average'])
# Total Transaction Count table query
cursor.execute(f"SELECT SUM(Transaction_count), AVG(Transaction_count) FROM aggregated_transaction WHERE State = '{st_tr_st}' AND Year ='{st_tr_yr}' AND Quarter = '{st_tr_qtr}';")
st_tr_co_qry_rslt = cursor.fetchall()
df_st_tr_co_qry_rslt = pd.DataFrame(np.array(st_tr_co_qry_rslt), columns=['Total','Average'])
df_st_tr_co_qry_rslt1 = df_st_tr_co_qry_rslt.set_index(['Average'])
# --------- / Output / -------- #
# ----- / State wise Transaction Analysis bar chart / ------ #
df_st_tr_tab_bar_qry_rslt1['Transaction_type'] = df_st_tr_tab_bar_qry_rslt1['Transaction_type'].astype(str)
df_st_tr_tab_bar_qry_rslt1['Transaction_amount'] = df_st_tr_tab_bar_qry_rslt1['Transaction_amount'].astype(float)
df_st_tr_tab_bar_qry_rslt1_fig = px.bar(df_st_tr_tab_bar_qry_rslt1 , x = 'Transaction_type', y ='Transaction_amount', color ='Transaction_amount', color_continuous_scale = 'thermal', title = 'Transaction Analysis Chart', height = 500,)
df_st_tr_tab_bar_qry_rslt1_fig.update_layout(title_font=dict(size=33),title_font_color='#6739b7')
st.plotly_chart(df_st_tr_tab_bar_qry_rslt1_fig,use_container_width=True)
# ------ / State wise Total Transaction calculation Table / ---- #
st.header(':violet[Total calculation]')
col4, col5 = st.columns(2)
with col4:
st.subheader('Transaction Analysis')
st.dataframe(df_st_tr_anly_tab_qry_rslt1)
with col5:
st.subheader('Transaction Amount')
st.dataframe(df_st_tr_am_qry_rslt1)
st.subheader('Transaction Count')
st.dataframe(df_st_tr_co_qry_rslt1)
# ----------------------------------------- / State wise User / ---------------------------------- #
with tab4:
col5, col6 = st.columns(2)
with col5:
st_us_st = st.selectbox('**Select State**',('andaman-&-nicobar-islands', 'andhra-pradesh', 'arunachal-pradesh','assam', 'bihar',
'chandigarh', 'chhattisgarh','dadra-&-nagar-haveli-&-daman-&-diu', 'delhi', 'goa', 'gujarat', 'haryana', 'himachal-pradesh',
'jammu-&-kashmir', 'jharkhand', 'karnataka', 'kerala', 'ladakh', 'lakshadweep', 'madhya-pradesh','maharashtra', 'manipur',
'meghalaya', 'mizoram', 'nagaland','odisha', 'puducherry', 'punjab', 'rajasthan', 'sikkim', 'tamil-nadu', 'telangana',
'tripura', 'uttar-pradesh', 'uttarakhand', 'west-bengal'),key='st_us_st')
with col6:
st_us_yr = st.selectbox('**Select Year**', ('2018','2019','2020','2021','2022'),key='st_us_yr')
# SQL Query
# User Analysis Bar chart query
cursor.execute(f"SELECT Quarter, SUM(User_Count) FROM aggregated_user WHERE State = '{st_us_st}' AND Year = '{st_us_yr}' GROUP BY Quarter;")
st_us_tab_qry_rslt = cursor.fetchall()
df_st_us_tab_qry_rslt = pd.DataFrame(np.array(st_us_tab_qry_rslt), columns=['Quarter', 'User Count'])
df_st_us_tab_qry_rslt1 = df_st_us_tab_qry_rslt.set_index(pd.Index(range(1, len(df_st_us_tab_qry_rslt)+1)))
# Total User Count table query
cursor.execute(f"SELECT SUM(User_Count), AVG(User_Count) FROM aggregated_user WHERE State = '{st_us_st}' AND Year = '{st_us_yr}';")
st_us_co_qry_rslt = cursor.fetchall()
df_st_us_co_qry_rslt = pd.DataFrame(np.array(st_us_co_qry_rslt), columns=['Total','Average'])
df_st_us_co_qry_rslt1 = df_st_us_co_qry_rslt.set_index(['Average'])
# --------- / Output / -------- #
# ----- / All India User Analysis Bar chart / ----- #
df_st_us_tab_qry_rslt1['Quarter'] = df_st_us_tab_qry_rslt1['Quarter'].astype(int)
df_st_us_tab_qry_rslt1['User Count'] = df_st_us_tab_qry_rslt1['User Count'].astype(int)
df_st_us_tab_qry_rslt1_fig = px.bar(df_st_us_tab_qry_rslt1 , x = 'Quarter', y ='User Count', color ='User Count', color_continuous_scale = 'thermal', title = 'User Analysis Chart', height = 500,)
df_st_us_tab_qry_rslt1_fig.update_layout(title_font=dict(size=33),title_font_color='#6739b7')
st.plotly_chart(df_st_us_tab_qry_rslt1_fig,use_container_width=True)
# ------ / State wise User Total User calculation Table / -----#
st.header(':violet[Total calculation]')
col3, col4 = st.columns(2)
with col3:
st.subheader('User Analysis')
st.dataframe(df_st_us_tab_qry_rslt1)
with col4:
st.subheader('User Count')
st.dataframe(df_st_us_co_qry_rslt1)
# ============================================== / Top categories / =========================================== #
else:
# Select tab
tab5, tab6 = st.tabs(['Transaction','User'])
# --------------------------------------- / All India Top Transaction / ---------------------------- #
with tab5:
top_tr_yr = st.selectbox('**Select Year**', ('2018','2019','2020','2021','2022'),key='top_tr_yr')
# SQL Query
# Top Transaction Analysis bar chart query
cursor.execute(f"SELECT State, SUM(Transaction_amount) As Transaction_amount FROM top_transaction WHERE Year = '{top_tr_yr}' GROUP BY State ORDER BY Transaction_amount DESC LIMIT 10;")
top_tr_tab_qry_rslt = cursor.fetchall()
df_top_tr_tab_qry_rslt = pd.DataFrame(np.array(top_tr_tab_qry_rslt), columns=['State', 'Top Transaction amount'])
df_top_tr_tab_qry_rslt1 = df_top_tr_tab_qry_rslt.set_index(pd.Index(range(1, len(df_top_tr_tab_qry_rslt)+1)))
# Top Transaction Analysis table query
cursor.execute(f"SELECT State, SUM(Transaction_amount) as Transaction_amount, SUM(Transaction_count) as Transaction_count FROM top_transaction WHERE Year = '{top_tr_yr}' GROUP BY State ORDER BY Transaction_amount DESC LIMIT 10;")
top_tr_anly_tab_qry_rslt = cursor.fetchall()
df_top_tr_anly_tab_qry_rslt = pd.DataFrame(np.array(top_tr_anly_tab_qry_rslt), columns=['State', 'Top Transaction amount','Total Transaction count'])
df_top_tr_anly_tab_qry_rslt1 = df_top_tr_anly_tab_qry_rslt.set_index(pd.Index(range(1, len(df_top_tr_anly_tab_qry_rslt)+1)))
# --------- / Output / -------- #
# ----- / All India Transaction Analysis Bar chart / ----- #
df_top_tr_tab_qry_rslt1['State'] = df_top_tr_tab_qry_rslt1['State'].astype(str)
df_top_tr_tab_qry_rslt1['Top Transaction amount'] = df_top_tr_tab_qry_rslt1['Top Transaction amount'].astype(float)
df_top_tr_tab_qry_rslt1_fig = px.bar(df_top_tr_tab_qry_rslt1 , x = 'State', y ='Top Transaction amount', color ='Top Transaction amount', color_continuous_scale = 'thermal', title = 'Top Transaction Analysis Chart', height = 600,)
df_top_tr_tab_qry_rslt1_fig.update_layout(title_font=dict(size=33),title_font_color='#6739b7')
st.plotly_chart(df_top_tr_tab_qry_rslt1_fig,use_container_width=True)
# ----- / All India Total Transaction calculation Table / ----- #
st.header(':violet[Total calculation]')
st.subheader('Top Transaction Analysis')
st.dataframe(df_top_tr_anly_tab_qry_rslt1)
# ------------------------- / All India Top User / ------------------ #
with tab6:
top_us_yr = st.selectbox('**Select Year**', ('2018','2019','2020','2021','2022'),key='top_us_yr')
# SQL Query
# Top User Analysis bar chart query
cursor.execute(f"SELECT State, SUM(Registered_User) AS Top_user FROM top_user WHERE Year='{top_us_yr}' GROUP BY State ORDER BY Top_user DESC LIMIT 10;")
top_us_tab_qry_rslt = cursor.fetchall()
df_top_us_tab_qry_rslt = pd.DataFrame(np.array(top_us_tab_qry_rslt), columns=['State', 'Total User count'])
df_top_us_tab_qry_rslt1 = df_top_us_tab_qry_rslt.set_index(pd.Index(range(1, len(df_top_us_tab_qry_rslt)+1)))
# --------- / Output / -------- #
# ----- / All India User Analysis Bar chart / ----- #
df_top_us_tab_qry_rslt1['State'] = df_top_us_tab_qry_rslt1['State'].astype(str)
df_top_us_tab_qry_rslt1['Total User count'] = df_top_us_tab_qry_rslt1['Total User count'].astype(float)
df_top_us_tab_qry_rslt1_fig = px.bar(df_top_us_tab_qry_rslt1 , x = 'State', y ='Total User count', color ='Total User count', color_continuous_scale = 'thermal', title = 'Top User Analysis Chart', height = 600,)
df_top_us_tab_qry_rslt1_fig.update_layout(title_font=dict(size=33),title_font_color='#6739b7')
st.plotly_chart(df_top_us_tab_qry_rslt1_fig,use_container_width=True)
# ----- / All India Total Transaction calculation Table / ----- #
st.header(':violet[Total calculation]')
st.subheader('Total User Analysis')
st.dataframe(df_top_us_tab_qry_rslt1)
# ========================================= / / / COMPLETED / / ===================================================== #