-
Notifications
You must be signed in to change notification settings - Fork 0
/
phonepe.py
1036 lines (745 loc) · 39.5 KB
/
phonepe.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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import streamlit as st
from streamlit_option_menu import option_menu
import psycopg2
import pandas as pd
import plotly.express as px
import requests
import json
from PIL import Image
#Dataframe Creation
#sql connection
mydb=psycopg2.connect(host="localhost",
user="postgres",
port="5432",
database="phonepe_data",
password="Kalpana05")
cursor=mydb.cursor()
#aggre_insurance_df
cursor.execute("SELECT * FROM aggregated_insurance")
mydb.commit()
talble1=cursor.fetchall()
Aggre_insurance=pd.DataFrame(talble1,columns=("States","Years","Quarter","Transaction_type","Transaction_count",
"Transaction_amount"))
#aggre_transaction_df
cursor.execute("SELECT * FROM aggregated_transaction")
mydb.commit()
talble2=cursor.fetchall()
Aggre_transaction=pd.DataFrame(talble2,columns=("States","Years","Quarter","Transaction_type","Transaction_count",
"Transaction_amount"))
#aggre_user_df
cursor.execute("SELECT * FROM aggregated_user")
mydb.commit()
talble3=cursor.fetchall()
Aggre_user=pd.DataFrame(talble3,columns=("States","Years","Quarter","Brands","Transaction_count",
"Percentage"))
#map_insurance_df
cursor.execute("SELECT * FROM map_insurance")
mydb.commit()
talble4=cursor.fetchall()
map_insurance=pd.DataFrame(talble4,columns=("States","Years","Quarter","District","Transaction_count",
"Transaction_amount"))
#map_transaction_df
cursor.execute("SELECT * FROM map_transaction")
mydb.commit()
talble5=cursor.fetchall()
map_transaction=pd.DataFrame(talble5,columns=("States","Years","Quarter","District","Transaction_count",
"Transaction_amount"))
#map_user_df
cursor.execute("SELECT * FROM map_user")
mydb.commit()
talble6=cursor.fetchall()
map_user=pd.DataFrame(talble6,columns=("States","Years","Quarter","District","RegisteredUser",
"AppOpens"))
#top_insurance_df
cursor.execute("SELECT * FROM top_insurance")
mydb.commit()
talble7=cursor.fetchall()
top_insurance=pd.DataFrame(talble7,columns=("States","Years","Quarter","Pincodes","Transaction_count",
"Transaction_amount"))
#top_transaction_df
cursor.execute("SELECT * FROM top_transaction")
mydb.commit()
talble8=cursor.fetchall()
top_transaction=pd.DataFrame(talble8,columns=("States","Years","Quarter","Pincodes","Transaction_count",
"Transaction_amount"))
#top_user_df
cursor.execute("SELECT * FROM top_user")
mydb.commit()
talble9=cursor.fetchall()
top_user=pd.DataFrame(talble9,columns=("States","Years","Quarter","Pincodes","RegisteredUsers",))
def Transaction_amount_count_Y(df,year):
tacy=df[df["Years"]==year]
tacy.reset_index(drop=True,inplace=True)
tacyg=tacy.groupby("States")[["Transaction_count","Transaction_amount"]].sum()
tacyg.reset_index(inplace=True)
col1,col2 = st.columns(2)
with col1:
fig_amount=px.bar(tacyg, x="States",y="Transaction_amount",title=f"{year} TRANSACTION AMOUNT",
color_discrete_sequence=px.colors.sequential.Aggrnyl,height=650,width=600)
st.plotly_chart(fig_amount)
with col2:
fig_count=px.bar(tacyg, x="States",y="Transaction_count",title=f"{year} TRANSACTION COUNT",
color_discrete_sequence=px.colors.sequential.Bluered_r,height=650,width=600)
st.plotly_chart(fig_count)
col1,col2= st.columns(2)
with col1:
url="https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson"
response= requests.get(url)
data1= json.loads(response.content)
states_name= []
for feature in data1["features"]:
states_name.append(feature["properties"]["ST_NM"])
states_name.sort()
fig_india_1= px.choropleth(tacyg, geojson=data1, locations="States", featureidkey="properties.ST_NM",
color="Transaction_amount", color_continuous_scale="Rainbow",
range_color=(tacyg["Transaction_amount"].min(), tacyg["Transaction_amount"].max()),
hover_name= "States",title= f"{year} TRANSACTION AMOUNT", fitbounds="locations",
height= 600, width= 600)
fig_india_1.update_geos(visible=False)
st.plotly_chart(fig_india_1)
with col2:
fig_india_2= px.choropleth(tacyg, geojson=data1, locations="States", featureidkey="properties.ST_NM",
color="Transaction_count", color_continuous_scale="Rainbow",
range_color=(tacyg["Transaction_count"].min(), tacyg["Transaction_count"].max()),
hover_name= "States",title= f"{year} TRANSACTION COUNT", fitbounds="locations",
height= 600, width= 600)
fig_india_2.update_geos(visible=False)
st.plotly_chart(fig_india_2)
return tacy
def Transaction_amount_count_Y_Q(df,quarter):
tacy=df[df["Quarter"]==quarter]
tacy.reset_index(drop=True,inplace=True)
tacyg=tacy.groupby("States")[["Transaction_count","Transaction_amount"]].sum()
tacyg.reset_index(inplace=True)
col1,col2= st.columns(2)
with col1:
fig_amount=px.bar(tacyg, x="States",y="Transaction_amount",title=f"{tacy['Years'].min()} YEAR {quarter} QUARTER TRANSACTION AMOUNT",
color_discrete_sequence=px.colors.sequential.Aggrnyl)
st.plotly_chart(fig_amount)
with col2:
fig_count=px.bar(tacyg, x="States",y="Transaction_count",title=f"{tacy['Years'].min()} YEAR {quarter} QUARTER TRANSACTION COUNT",
color_discrete_sequence=px.colors.sequential.Bluered_r)
st.plotly_chart(fig_count)
col1,col2= st.columns(2)
with col1:
url="https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson"
response= requests.get(url)
data1= json.loads(response.content)
states_name= []
for feature in data1["features"]:
states_name.append(feature["properties"]["ST_NM"])
states_name.sort()
fig_india_1= px.choropleth(tacyg, geojson=data1, locations="States", featureidkey="properties.ST_NM",
color="Transaction_amount", color_continuous_scale="Rainbow",
range_color=(tacyg["Transaction_amount"].min(), tacyg["Transaction_amount"].max()),
hover_name= "States",title= f"{tacy['Years'].min()} YEAR {quarter} QUARTER TRANSACTION AMOUNT", fitbounds="locations",
height= 600, width= 600)
fig_india_1.update_geos(visible=False)
st.plotly_chart(fig_india_1)
with col2:
fig_india_2= px.choropleth(tacyg, geojson=data1, locations="States", featureidkey="properties.ST_NM",
color="Transaction_count", color_continuous_scale="Rainbow",
range_color=(tacyg["Transaction_count"].min(), tacyg["Transaction_count"].max()),
hover_name= "States",title= f"{tacy['Years'].min()} YEAR {quarter} QUARTER TRANSACTION COUNT", fitbounds="locations",
height= 600, width= 600)
fig_india_2.update_geos(visible=False)
st.plotly_chart(fig_india_2)
return tacy
def Aggre_Tran_Transaction_type(df, state):
tacy=df[df["States"]== state]
tacy.reset_index(drop=True,inplace=True)
tacyg=tacy.groupby("Transaction_type")[["Transaction_count","Transaction_amount"]].sum()
tacyg.reset_index(inplace=True)
col1,col2=st.columns(2)
with col1:
fig_pie_1=px.pie(data_frame= tacyg, names= "Transaction_type", values="Transaction_amount",
width=600, title= f"{state.upper()} TRANSACTION AMOUNT", hole=0.5,)
st.plotly_chart(fig_pie_1)
with col2:
fig_pie_2=px.pie(data_frame= tacyg, names= "Transaction_type", values="Transaction_count",
width=600, title=f"{state.upper()} TRANSACTION COUNT", hole=0.5,)
st.plotly_chart(fig_pie_2)
# Aggre_User_analysis_1
def Aggre_user_plot_1(df,year):
aguy=df[df["Years"]==year]
aguy.reset_index(drop= True, inplace= True)
aguyg=pd.DataFrame(aguy.groupby("Brands")["Transaction_count"].sum())
aguyg.reset_index(inplace=True)
fig_bar_1=px.bar(aguyg, x="Brands",y="Transaction_count",title=f"{year} BRANDS AND TRANSACTION COUNT",
width=1000,color_discrete_sequence= px.colors.sequential.haline_r,hover_name="Brands")
st.plotly_chart(fig_bar_1)
return aguy
#Aggre_user_analysis_2
def Aggre_user_plot_2(df,quarter):
aguyq= df[df["Quarter"]==quarter]
aguyq.reset_index(drop=True, inplace=True)
aguyqg=pd.DataFrame(aguyq.groupby("Brands")["Transaction_count"].sum())
aguyqg.reset_index(inplace= True)
fig_bar_1= px.bar(aguyqg, x="Brands",y="Transaction_count", title= f"{quarter} QUARTER, BRANDS AND TRANSACTION COUNT",
width=1000, color_discrete_sequence= px.colors.sequential.Magenta_r,hover_name="Brands")
st.plotly_chart(fig_bar_1)
return aguyq
#Aggre_user_analysis_3
def Aggre_user_plot_3(df,state):
auyqs= df[df["States"]==state]
auyqs.reset_index(drop= True, inplace=True)
fig_line_1=px.line(auyqs, x="Brands", y= "Transaction_count",hover_data="Percentage",
title=f"{state.upper()} BRANDS, TRANSACTION COUNT, PERCENTAGE", width=1000,markers= True)
st.plotly_chart(fig_line_1)
#Map_insurance_District
def Map_insur_District(df, state):
tacy=df[df["States"]== state]
tacy.reset_index(drop=True,inplace=True)
tacyg=tacy.groupby("District")[["Transaction_count","Transaction_amount"]].sum()
tacyg.reset_index(inplace=True)
col1,col2=st.columns(2)
with col1:
fig_bar_1=px.bar(tacyg, x="Transaction_amount",y="District", orientation= "h",height=600,
title=f"{state.upper()} DISTRICT AND TRANSACTION AMOUNT",color_discrete_sequence=px.colors.sequential.Mint_r)
st.plotly_chart(fig_bar_1)
with col2:
fig_bar_2=px.bar(tacyg, x="Transaction_count",y="District", orientation= "h",height=600,
title=f"{state.upper()} DISTRICT AND TRANSACTION COUNT",color_discrete_sequence=px.colors.sequential.Bluered)
st.plotly_chart(fig_bar_2)
# map_user_plot_1
def map_user_plot_1(df,year):
muy=df[df["Years"]==year]
muy.reset_index(drop= True, inplace= True)
muyg=(muy.groupby("States")[["RegisteredUser","AppOpens"]].sum())
muyg.reset_index(inplace=True)
fig_line_1=px.line(muyg, x="States", y= ["RegisteredUser", "AppOpens"],
title=f"{year} REGISTEREDUSER APPOPENS", width=1000, height=800, markers= True)
st.plotly_chart(fig_line_1)
return muy
#map_user_plot_2
def map_user_plot_2(df,quarter):
muyq=df[df["Quarter"]==quarter]
muyq.reset_index(drop= True, inplace= True)
muyqg=(muyq.groupby("States")[["RegisteredUser","AppOpens"]].sum())
muyqg.reset_index(inplace=True)
fig_line_1=px.line(muyqg, x="States", y= ["RegisteredUser", "AppOpens"],
title=f"{df['Years'].min()} YEARS {quarter} QUARTER REGISTEREDUSER APPOPENS", width=1000, height=800, markers= True,
color_discrete_sequence=px.colors.sequential.Rainbow)
st.plotly_chart(fig_line_1)
return muyq
#map_user_plot_3
def map_user_plot_3(df,states):
muyqs= df[df["States"]==states]
muyqs.reset_index(drop=True, inplace=True)
fig_map_user_bar_1=px.bar(muyqs, x="RegisteredUser",y="District", orientation="h",
title=f"{states.upper()} REGISTERED USER",height=800, color_discrete_sequence=px.colors.sequential.Reds_r)
st.plotly_chart(fig_map_user_bar_1)
fig_map_user_bar_2=px.bar(muyqs, x="AppOpens",y="District", orientation="h",
title=f"{states.upper()} APPOPENS ",height=800, color_discrete_sequence=px.colors.sequential.Bluered)
st.plotly_chart(fig_map_user_bar_2)
# top_insurance_plot_1
def Top_insurance_plot_1(df, state):
tiy=df[df["States"]==state]
tiy.reset_index(drop= True, inplace= True)
col1,col2=st.columns(2)
with col1:
fig_top_insur_bar_1= px.bar(tiy, x="Quarter", y="Transaction_amount", hover_data="Pincodes",
title="TRANSACTION AMOUNT", height=600,width=600, color_discrete_sequence=px.colors.sequential.Redor_r)
st.plotly_chart(fig_top_insur_bar_1)
with col2:
fig_top_insur_bar_2= px.bar(tiy, x="Quarter", y="Transaction_count", hover_data="Pincodes",
title="TRANSACTION COUNT", height=600,width=600, color_discrete_sequence=px.colors.sequential.Redor)
st.plotly_chart(fig_top_insur_bar_2)
#top_user_plot_1
def top_user_plot_1(df,year):
tuy=df[df["Years"]==year]
tuy.reset_index(drop= True, inplace= True)
tuyg= pd.DataFrame(tuy.groupby(["States", "Quarter"])["RegisteredUsers"].sum())
tuyg.reset_index(inplace=True)
fig_top_plot_1= px.bar(tuyg, x="States", y="RegisteredUsers", color="Quarter", width=1000, height= 800,
color_discrete_sequence= px.colors.sequential.Burgyl, hover_name= "States",
title=f"{year} REGISTERED USERS")
st.plotly_chart(fig_top_plot_1)
return tuy
#top_user_plot_2
def top_user_plot_2(df,state):
tuys=df[df["States"]==state]
tuys.reset_index(drop= True, inplace= True)
fig_top_plot_2= px.bar(tuys, x="Quarter", y="RegisteredUsers", title="REGISTERED USERS, PINCODES, QUARTER",
width=1000, height=800, color="RegisteredUsers",hover_data="Pincodes",
color_continuous_scale= px.colors.sequential.Magenta)
st.plotly_chart(fig_top_plot_2)
#sql connection
def top_chart_transaction_amount(table_name):
mydb=psycopg2.connect(host="localhost",
user="postgres",
port="5432",
database="phonepe_data",
password="Kalpana05")
cursor=mydb.cursor()
#plot_1
query1=f'''SELECT states, SUM(transaction_amount) AS transaction_amout
FROM {table_name}
GROUP BY states
ORDER BY transaction_amout DESC
LIMIT 10;'''
cursor.execute(query1)
table_1=cursor.fetchall()
mydb.commit()
df_1=pd.DataFrame(table_1,columns=("states","transaction_amount"))
col1,col2=st.columns(2)
with col1:
fig_amount=px.bar(df_1, x="states",y="transaction_amount",title="TOP 10 OF TRANSACTION AMOUNT",
color_discrete_sequence=px.colors.sequential.Aggrnyl,width=600,height=600,hover_name="states",)
st.plotly_chart(fig_amount)
#plot_2
query2=f'''SELECT states, SUM(transaction_amount) AS transaction_amount
FROM {table_name}
GROUP BY states
ORDER BY transaction_amount
LIMIT 10;'''
cursor.execute(query2)
table_2=cursor.fetchall()
mydb.commit()
df_2=pd.DataFrame(table_2,columns=("states","transaction_amount"))
with col2:
fig_amount_2=px.bar(df_2, x="states",y="transaction_amount",title="LAST 10 OF TRANSACTION AMOUNT",
color_discrete_sequence=px.colors.sequential.Blackbody_r,width=600,height=600,hover_name="states",)
st.plotly_chart(fig_amount_2)
#plot_3
query3=f'''SELECT states, AVG(transaction_amount) AS transaction_amount
FROM {table_name}
GROUP BY states
ORDER BY transaction_amount;'''
cursor.execute(query3)
table_3=cursor.fetchall()
mydb.commit()
df_3=pd.DataFrame(table_3,columns=("states","transaction_amount"))
fig_amount_3=px.bar(df_3, y="states",x="transaction_amount",title="AVERAGE OF TRANSACTION AMOUNT",orientation="h",
color_discrete_sequence=px.colors.sequential.Blues,width=800,height=600,hover_name="states",)
st.plotly_chart(fig_amount_3)
#sql connection
def top_chart_transaction_count(table_name):
mydb=psycopg2.connect(host="localhost",
user="postgres",
port="5432",
database="phonepe_data",
password="Kalpana05")
cursor=mydb.cursor()
#plot_1
query1=f'''SELECT states, SUM(transaction_count) AS transaction_count
FROM {table_name}
GROUP BY states
ORDER BY transaction_count DESC
LIMIT 10;'''
cursor.execute(query1)
table_1=cursor.fetchall()
mydb.commit()
df_1=pd.DataFrame(table_1,columns=("states","transaction_count"))
col1,col2= st.columns(2)
with col1:
fig_amount=px.bar(df_1, x="states",y="transaction_count",title="TOP 10 OF TRANSACTION COUNT",
color_discrete_sequence=px.colors.sequential.Aggrnyl,width=600,height=600,hover_name="states",)
st.plotly_chart(fig_amount)
#plot_2
query2=f'''SELECT states, SUM(transaction_count) AS transaction_count
FROM {table_name}
GROUP BY states
ORDER BY transaction_count
LIMIT 10;'''
cursor.execute(query2)
table_2=cursor.fetchall()
mydb.commit()
df_2=pd.DataFrame(table_2,columns=("states","transaction_count"))
with col2:
fig_amount_2=px.bar(df_2, x="states",y="transaction_count",title="LAST 10 OF TRANSACTION COUNT",
color_discrete_sequence=px.colors.sequential.Blackbody_r,width=600,height=600,hover_name="states",)
st.plotly_chart(fig_amount_2)
#plot_3
query3=f'''SELECT states, AVG(transaction_count) AS transaction_count
FROM {table_name}
GROUP BY states
ORDER BY transaction_count;'''
cursor.execute(query3)
table_3=cursor.fetchall()
mydb.commit()
df_3=pd.DataFrame(table_3,columns=("states","transaction_count"))
fig_amount_3=px.bar(df_3, y="states",x="transaction_count",title="AVERAGE OF TRANSACTION COUNT",orientation="h",
color_discrete_sequence=px.colors.sequential.Blues,width=800,height=1000,hover_name="states",)
st.plotly_chart(fig_amount_3)
#sql connection
def top_chart_registered_user(table_name,state):
mydb=psycopg2.connect(host="localhost",
user="postgres",
port="5432",
database="phonepe_data",
password="Kalpana05")
cursor=mydb.cursor()
#plot_1
query1=f'''SELECT districts, SUM(registereduser) AS registereduser
FROM {table_name}
WHERE states='{state}'
GROUP BY districts
ORDER BY registereduser DESC
LIMIT 10;'''
cursor.execute(query1)
table_1=cursor.fetchall()
mydb.commit()
df_1=pd.DataFrame(table_1,columns=("districts","registereduser"))
col1,col2= st.columns(2)
with col1:
fig_amount=px.bar(df_1, x="districts",y="registereduser",title="TOP 10 OF REGISTERED USER",
color_discrete_sequence=px.colors.sequential.Aggrnyl,width=600,height=600,hover_name="districts",)
st.plotly_chart(fig_amount)
#plot_2
query2=f'''SELECT districts, SUM(registereduser) AS registereduser
FROM {table_name}
WHERE states='{state}'
GROUP BY districts
ORDER BY registereduser
LIMIT 10;'''
cursor.execute(query2)
table_2=cursor.fetchall()
mydb.commit()
df_2=pd.DataFrame(table_2,columns=("districts","registereduser"))
with col2:
fig_amount_2=px.bar(df_2, x="districts",y="registereduser",title="LAST 10 REGISTERED USER",
color_discrete_sequence=px.colors.sequential.Blackbody_r,width=600,height=600,hover_name="districts",)
st.plotly_chart(fig_amount_2)
#plot_3
query3=f'''SELECT districts, AVG(registereduser) AS registereduser
FROM {table_name}
WHERE states='{state}'
GROUP BY districts
ORDER BY registereduser;'''
cursor.execute(query3)
table_3=cursor.fetchall()
mydb.commit()
df_3=pd.DataFrame(table_3,columns=("districts","registereduser"))
fig_amount_3=px.bar(df_3, y="districts",x="registereduser",title="AVERAGE OF REGISTERED USER",orientation="h",
color_discrete_sequence=px.colors.sequential.Blues,width=800,height=1000,hover_name="districts",)
st.plotly_chart(fig_amount_3)
#sql connection
def top_chart_appopens(table_name,state):
mydb=psycopg2.connect(host="localhost",
user="postgres",
port="5432",
database="phonepe_data",
password="Kalpana05")
cursor=mydb.cursor()
#plot_1
query1=f'''SELECT districts, SUM(appopens) AS appopens
FROM {table_name}
WHERE states='{state}'
GROUP BY districts
ORDER BY appopens DESC
LIMIT 10;'''
cursor.execute(query1)
table_1=cursor.fetchall()
mydb.commit()
df_1=pd.DataFrame(table_1,columns=("districts","appopens"))
col1,col2=st.columns(2)
with col1:
fig_amount=px.bar(df_1, x="districts",y="appopens",title="TOP 10 OF APPOPENS",
color_discrete_sequence=px.colors.sequential.Aggrnyl,width=600,height=600,hover_name="districts",)
st.plotly_chart(fig_amount)
#plot_2
query2=f'''SELECT districts, SUM(appopens) AS appopens
FROM {table_name}
WHERE states='{state}'
GROUP BY districts
ORDER BY appopens
LIMIT 10;'''
cursor.execute(query2)
table_2=cursor.fetchall()
mydb.commit()
df_2=pd.DataFrame(table_2,columns=("districts","appopens"))
with col2:
fig_amount_2=px.bar(df_2, x="districts",y="appopens",title="LAST 10 APPOPENS",
color_discrete_sequence=px.colors.sequential.Blackbody_r,width=600,height=600,hover_name="districts",)
st.plotly_chart(fig_amount_2)
#plot_3
query3=f'''SELECT districts, AVG(appopens) AS appopens
FROM {table_name}
WHERE states='{state}'
GROUP BY districts
ORDER BY appopens;'''
cursor.execute(query3)
table_3=cursor.fetchall()
mydb.commit()
df_3=pd.DataFrame(table_3,columns=("districts","appopens"))
fig_amount_3=px.bar(df_3, y="districts",x="appopens",title="AVERAGE OF APPOPENS",orientation="h",
color_discrete_sequence=px.colors.sequential.Reds_r,width=800,height=1000,hover_name="districts",)
st.plotly_chart(fig_amount_3)
#sql connection
def top_chart_registered_users(table_name):
mydb=psycopg2.connect(host="localhost",
user="postgres",
port="5432",
database="phonepe_data",
password="Kalpana05")
cursor=mydb.cursor()
#plot_1
query1=f'''SELECT states, SUM(registeredusers) AS registeredusers
FROM {table_name}
GROUP BY states
ORDER BY registeredusers DESC
LIMIT 10;'''
cursor.execute(query1)
table_1=cursor.fetchall()
mydb.commit()
df_1=pd.DataFrame(table_1,columns=("states","registeredusers"))
col1,col2=st.columns(2)
with col1:
fig_amount=px.bar(df_1, x="states",y="registeredusers",title="TOP 10 OF REGISTERED USERS",
color_discrete_sequence=px.colors.sequential.Aggrnyl,width=600,height=600,hover_name="states",)
st.plotly_chart(fig_amount)
#plot_2
query2=f'''SELECT states, SUM(registeredusers) AS registeredusers
FROM {table_name}
GROUP BY states
ORDER BY registeredusers
LIMIT 10;'''
cursor.execute(query2)
table_2=cursor.fetchall()
mydb.commit()
df_2=pd.DataFrame(table_2,columns=("states","registeredusers"))
with col2:
fig_amount_2=px.bar(df_2, x="states",y="registeredusers",title="LAST 10 REGISTERED USERS",
color_discrete_sequence=px.colors.sequential.Blackbody_r,width=600,height=600,hover_name="states",)
st.plotly_chart(fig_amount_2)
#plot_3
query3=f'''SELECT states, AVG(registeredusers) AS registeredusers
FROM {table_name}
GROUP BY states
ORDER BY registeredusers;'''
cursor.execute(query3)
table_3=cursor.fetchall()
mydb.commit()
df_3=pd.DataFrame(table_3,columns=("states","registeredusers"))
fig_amount_3=px.bar(df_3, y="states",x="registeredusers",title="AVERAGE OF REGISTERED USERS",orientation="h",
color_discrete_sequence=px.colors.sequential.Blues,width=800,height=1000,hover_name="states",)
st.plotly_chart(fig_amount_3)
#Streamlit part
st.set_page_config(layout="wide")
st.title("PHONEPE DATA VISUALIZATION AND EXPLORATION")
with st.sidebar:
select=option_menu("Main Menu",["HOME","DATA EXPLORATION","TOP CHARTS"])
if select == "HOME":
col1,col2=st.columns(2)
with col1:
st.header("PHONEPE")
st.subheader("INDIA'S BEST TRANSACTION APP")
st.markdown("PhonePe is an Indian digital payments and financial technology company")
st.write("****PhonePe is considered a safe and secure app****")
st.write("****Credit & Debit card linking****")
st.write("****Linked to Multiple Bank Accounts****")
st.write("****End-to-End Encryption****")
st.write("****PIN Authorization****")
st.download_button("DOWNLOAD THE APP NOW","https://www.phonepe.com/app-download/")
with col2:
st.video(r"C:\Users\91934\OneDrive\Desktop\phonepe\videos\VID-20240716-WA0001.mp4")
col3,col4=st.columns(2)
with col3:
st.image(r"C:\Users\91934\OneDrive\Desktop\phonepe\images\images.jpeg",width=350)
with col4:
st.write("****Easy Transactions****")
st.write("****One App For All Your Payments****")
st.write("****Your Bank Account Is All You Need****")
st.write("****Multiple Payment Modes****")
st.write("****1.Direct Transfer & More****")
st.write("****2.QR Code Payments****")
st.write("****Get Rewards and Cashback****")
col5,col6=st.columns(2)
with col5:
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.markdown(" ")
st.write("****No Wallet Top-Up Required****")
st.write("****Pay Directly From Any Bank To Any Bank A/C****")
st.write("****Instantly & free****")
with col6:
st.video(r"C:\Users\91934\OneDrive\Desktop\phonepe\videos\VID-20240716-WA0002.mp4")
elif select =="DATA EXPLORATION":
tab1,tab2,tab3=st.tabs(["Aggregated Analysis","Map Analysis","Top Analysis"])
with tab1:
method=st.radio("Select The Method",["Insurance Analysis","Transaction Analysis","User Analysis"])
if method == "Insurance Analysis":
col1,col2=st.columns(2)
with col1:
years=st.slider("Select The Year",Aggre_insurance["Years"].min(),Aggre_insurance["Years"].max(),Aggre_insurance["Years"].min())
tac_Y= Transaction_amount_count_Y(Aggre_insurance,years)
col1,col2= st.columns(2)
with col1:
quarters=st.slider("Select The Quarter",tac_Y["Quarter"].min(),tac_Y["Quarter"].max(),tac_Y["Quarter"].min())
Transaction_amount_count_Y_Q(tac_Y,quarters)
elif method== "Transaction Analysis":
col1,col2=st.columns(2)
with col1:
years=st.slider("Select The Year",Aggre_transaction["Years"].min(),Aggre_transaction["Years"].max(),Aggre_transaction["Years"].min())
Aggre_tran_tac_Y= Transaction_amount_count_Y(Aggre_transaction,years)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State", Aggre_tran_tac_Y["States"].unique())
Aggre_Tran_Transaction_type(Aggre_tran_tac_Y, states)
col1,col2= st.columns(2)
with col1:
quarters=st.slider("Select The Quarter",Aggre_tran_tac_Y["Quarter"].min(),Aggre_tran_tac_Y["Quarter"].max(),Aggre_tran_tac_Y["Quarter"].min())
Aggre_tran_tac_Y_Q= Transaction_amount_count_Y_Q(Aggre_tran_tac_Y, quarters)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State_Ty", Aggre_tran_tac_Y_Q["States"].unique())
Aggre_Tran_Transaction_type(Aggre_tran_tac_Y_Q, states)
elif method =="User Analysis":
col1,col2=st.columns(2)
with col1:
years=st.slider("Select The Year",Aggre_user["Years"].min(),Aggre_user["Years"].max(),Aggre_user["Years"].min())
Aggre_user_Y= Aggre_user_plot_1(Aggre_user,years)
col1,col2= st.columns(2)
with col1:
quarters=st.slider("Select The Quarter",Aggre_user_Y["Quarter"].min(),Aggre_user_Y["Quarter"].max(),Aggre_user_Y["Quarter"].min())
Aggre_user_Y_Q= Aggre_user_plot_2(Aggre_user_Y, quarters)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State", Aggre_user_Y_Q["States"].unique())
Aggre_user_plot_3(Aggre_user_Y_Q, states)
with tab2:
method_2=st.radio("Select The Method",["Map Insurance","Map Transaction","Map User"])
if method_2=="Map Insurance":
col1,col2= st.columns(2)
with col1:
years=st.slider("Select The Year_mi",map_insurance["Years"].min(),map_insurance["Years"].max(),map_insurance["Years"].min())
map_insur_tac_Y= Transaction_amount_count_Y(map_insurance,years)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State_mi", map_insur_tac_Y["States"].unique())
Map_insur_District(map_insur_tac_Y, states)
col1,col2= st.columns(2)
with col1:
quarters=st.slider("Select The Quarter_mi",map_insur_tac_Y["Quarter"].min(),map_insur_tac_Y["Quarter"].max(),map_insur_tac_Y["Quarter"].min())
map_insur_tac_Y_Q= Transaction_amount_count_Y_Q(map_insur_tac_Y, quarters)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State_Ty", map_insur_tac_Y_Q["States"].unique())
Map_insur_District(map_insur_tac_Y_Q, states)
elif method_2=="Map Transaction":
col1,col2= st.columns(2)
with col1:
years=st.slider("Select The Year_mt",map_transaction["Years"].min(),map_transaction["Years"].max(),map_transaction["Years"].min())
map_tran_tac_Y= Transaction_amount_count_Y(map_transaction,years)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State_mt", map_tran_tac_Y["States"].unique())
Map_insur_District(map_tran_tac_Y, states)
col1,col2= st.columns(2)
with col1:
quarters=st.slider("Select The Quarter_mt",map_tran_tac_Y["Quarter"].min(),map_tran_tac_Y["Quarter"].max(),map_tran_tac_Y["Quarter"].min())
map_tran_tac_Y_Q= Transaction_amount_count_Y_Q(map_tran_tac_Y, quarters)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State_Ty", map_tran_tac_Y_Q["States"].unique())
Map_insur_District(map_tran_tac_Y_Q, states)
elif method_2=="Map User":
col1,col2= st.columns(2)
with col1:
years=st.slider("Select The Year_mu",map_user["Years"].min(),map_user["Years"].max(),map_user["Years"].min())
map_user_Y= map_user_plot_1(map_user, years)
col1,col2= st.columns(2)
with col1:
quarters=st.slider("Select The Quarter_mu",map_user_Y["Quarter"].min(),map_user_Y["Quarter"].max(),map_user_Y["Quarter"].min())
map_user_Y_Q= map_user_plot_2(map_user_Y, quarters)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State_mu", map_user_Y_Q["States"].unique())
map_user_plot_3(map_user_Y_Q, states)
with tab3:
method_3=st.radio("Select The Method",["Top Insurance","Top Transaction","Top User"])
if method_3=="Top Insurance":
col1,col2= st.columns(2)
with col1:
years=st.slider("Select The Year_TI",top_insurance["Years"].min(),top_insurance["Years"].max(),top_insurance["Years"].min())
top_insur_tac_Y= Transaction_amount_count_Y(top_insurance,years)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State_ti", top_insur_tac_Y["States"].unique())
Top_insurance_plot_1(top_insur_tac_Y, states)
col1,col2= st.columns(2)
with col1:
quarters=st.slider("Select The Quarter_TI",top_insur_tac_Y["Quarter"].min(),top_insur_tac_Y["Quarter"].max(),top_insur_tac_Y["Quarter"].min())
top_insur_tac_Y_Q= Transaction_amount_count_Y_Q(top_insur_tac_Y, quarters)
elif method_3=="Top Transaction":
col1,col2= st.columns(2)
with col1:
years=st.slider("Select The Year_TT",top_transaction["Years"].min(),top_transaction["Years"].max(),top_transaction["Years"].min())
top_tran_tac_Y= Transaction_amount_count_Y(top_transaction,years)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State_TT",top_tran_tac_Y["States"].unique())
Top_insurance_plot_1(top_tran_tac_Y, states)
col1,col2= st.columns(2)
with col1:
quarters=st.slider("Select The Quarter_TT",top_tran_tac_Y["Quarter"].min(),top_tran_tac_Y["Quarter"].max(),top_tran_tac_Y["Quarter"].min())
top_tran_tac_Y_Q= Transaction_amount_count_Y_Q(top_tran_tac_Y, quarters)
elif method_3=="Top User":
col1,col2= st.columns(2)
with col1:
years=st.slider("Select The Year_TU",top_user["Years"].min(),top_user["Years"].max(),top_user["Years"].min())
top_user_Y= top_user_plot_1(top_user,years)
col1,col2=st.columns(2)
with col1:
states=st.selectbox("Select The State_TU",top_user_Y["States"].unique())
top_user_plot_2(top_user_Y, states)
elif select =="TOP CHARTS":
question=st.selectbox("Select the Question",["1.Transaction Amount and Count of Aggregated Insurance",
"2.Transaction Amount and Count of Map map_insurance",
"3.Transaction Amount and Count of Top Insurance",
"4.Transaction Amount and Count of Aggregated Transaction",
"5.Transaction Amount and Count of Map Transaction",
"6.Transaction Amount and Count of Top Transaction",
"7.Transaction Count of Aggregated User" ,
"8.Registered users of Map User",
"9.App opens of Map User",
"10.Registered users of Top User",
])
if question == "1.Transaction Amount and Count of Aggregated Insurance":
st.subheader("TRANSACTION AMOUNT")
top_chart_transaction_amount("aggregated_insurance")
st.subheader("TRANSACTION COUNT")
top_chart_transaction_count("aggregated_insurance")
elif question == "2.Transaction Amount and Count of Map map_insurance":
st.subheader("TRANSACTION AMOUNT")
top_chart_transaction_amount("map_insurance")
st.subheader("TRANSACTION COUNT")
top_chart_transaction_count("map_insurance")
elif question == "3.Transaction Amount and Count of Top Insurance":
st.subheader("TRANSACTION AMOUNT")
top_chart_transaction_amount("top_insurance")
st.subheader("TRANSACTION COUNT")
top_chart_transaction_count("top_insurance")
elif question == "4.Transaction Amount and Count of Aggregated Transaction":
st.subheader("TRANSACTION AMOUNT")
top_chart_transaction_amount("aggregated_transaction")
st.subheader("TRANSACTION COUNT")
top_chart_transaction_count("aggregated_transaction")
elif question == "5.Transaction Amount and Count of Map Transaction":