-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhonepePulse.py
333 lines (282 loc) · 20.1 KB
/
PhonepePulse.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
# Importing Libraries
import sys
sys.path.append("/opt/anaconda3/lib/python3.11/site-packages")
import pandas as pd
import mysql.connector as sql
import streamlit as st
import plotly.express as px
import os
import json
from streamlit_option_menu import option_menu
from PIL import Image
# Setting up page configuration
icon = Image.open(r"D:\Dimpu\ProjectWorks\Python\PhonepePulseData\Data\ICN.png")
st.set_page_config(page_title= "Phonepe Pulse Data Visualization",
page_icon= icon,
layout= "wide",
initial_sidebar_state= "expanded",
menu_items={'About': """# This dashboard app is created by *Prasanna*!
Data has been cloned from Phonepe Pulse Github Repo"""})
st.sidebar.header(":wave: :violet[**Hello! Welcome to the dashboard**]")
# #To clone the Github Pulse repository use the following code
# Reference Syntax - Repo.clone_from("Clone Url", "Your working directory")
# Creating connection with mysql workbench
mydb = sql.connect(host="localhost",
user="root",
password="Denjerry&7",
database= "phonepepulse",
port = "3306"
)
mycursor = mydb.cursor(buffered=True)
# Creating option menu in the side bar
with st.sidebar:
selected = option_menu("Menu", ["Home","Top Charts","Explore Data","About"],
icons=["house","graph-up-arrow","bar-chart-line", "exclamation-circle"],
menu_icon= "menu-button-wide",
default_index=0,
styles={"nav-link": {"font-size": "20px", "text-align": "left", "margin": "-2px", "--hover-color": "#6F36AD"},
"nav-link-selected": {"background-color": "#6F36AD"}})
# MENU 1 - HOME
if selected == "Home":
st.markdown("# :violet[PhonePe Pulse Data Visualization and Exploration]")
st.markdown("## :violet[A User-Friendly Tool Using Streamlit and Plotly]")
col1,col2 = st.columns([3,1],gap="medium")
with col1:
st.write(" ")
st.write(" ")
st.markdown("### :violet[Domain :] Fintech")
st.markdown("### :violet[Technologies used :] Github Cloning, Python, Pandas, MySQL, mysql-connector-python, Streamlit, and Plotly.")
st.markdown("### :violet[Overview :] In this streamlit web app you can visualize the phonepe pulse data and gain lot of insights on transactions, number of users, top 10 state, district, pincode and which brand has most number of users and so on. Bar charts, Pie charts and Geo map visualization are used to get some insights.")
# MENU 2 - TOP CHARTS
if selected == "Top Charts":
st.markdown("## :violet[Top Charts]")
Type = st.sidebar.selectbox("**Type**", ("Transactions", "Users"))
colum1,colum2= st.columns([1,1.5],gap="large")
with colum1:
Year = st.slider("**Year**", min_value=2018, max_value=2022)
Quarter = st.slider("Quarter", min_value=1, max_value=4)
with colum2:
st.info(
"""
#### From this menu we can get insights like :
- Overall ranking on a particular Year and Quarter.
- Top 10 State, District, Pincode based on Total number of transaction and Total amount spent on phonepe.
- Top 10 State, District, Pincode based on Total phonepe users and their app opening frequency.
- Top 10 mobile brands and its percentage based on the how many people use phonepe.
""",icon="🔍"
)
# Top Charts - TRANSACTIONS
if Type == "Transactions":
col1,col2,col3 = st.columns([1,1,1],gap="small")
with col1:
st.markdown("### :violet[State]")
mycursor.execute(f"select state, sum(Transaction_count) as Total_Transactions_Count, sum(Transaction_amount) as Total from agg_trans where year = {Year} and quarter = {Quarter} group by state order by Total desc limit 10")
df = pd.DataFrame(mycursor.fetchall(), columns=['State', 'Transactions_Count','Total_Amount'])
fig = px.pie(df, values='Total_Amount',
names='State',
title='Top 10',
color_discrete_sequence=px.colors.sequential.Agsunset,
hover_data=['Transactions_Count'],
labels={'Transactions_Count':'Transactions_Count'})
fig.update_traces(textposition='inside', textinfo='percent+label')
st.plotly_chart(fig,use_container_width=True)
with col2:
st.markdown("### :violet[District]")
mycursor.execute(f"select district , sum(Count) as Total_Count, sum(Amount) as Total from map_trans where year = {Year} and quarter = {Quarter} group by district order by Total desc limit 10")
df = pd.DataFrame(mycursor.fetchall(), columns=['District', 'Transactions_Count','Total_Amount'])
fig = px.pie(df, values='Total_Amount',
names='District',
title='Top 10',
color_discrete_sequence=px.colors.sequential.Agsunset,
hover_data=['Transactions_Count'],
labels={'Transactions_Count':'Transactions_Count'})
fig.update_traces(textposition='inside', textinfo='percent+label')
st.plotly_chart(fig,use_container_width=True)
with col3:
st.markdown("### :violet[Pincode]")
mycursor.execute(f"select pincode, sum(Transaction_count) as Total_Transactions_Count, sum(Transaction_amount) as Total from top_trans where year = {Year} and quarter = {Quarter} group by pincode order by Total desc limit 10")
df = pd.DataFrame(mycursor.fetchall(), columns=['Pincode', 'Transactions_Count','Total_Amount'])
fig = px.pie(df, values='Total_Amount',
names='Pincode',
title='Top 10',
color_discrete_sequence=px.colors.sequential.Agsunset,
hover_data=['Transactions_Count'],
labels={'Transactions_Count':'Transactions_Count'})
fig.update_traces(textposition='inside', textinfo='percent+label')
st.plotly_chart(fig,use_container_width=True)
# Top Charts - USERS
if Type == "Users":
col1,col2,col3,col4 = st.columns([2,2,2,2],gap="small")
with col1:
st.markdown("### :violet[Brands]")
if Year == 2022 and Quarter in [2,3,4]:
st.markdown("#### Sorry No Data to Display for 2022 Qtr 2,3,4")
else:
mycursor.execute(f"select brands, sum(count) as Total_Count, avg(percentage)*100 as Avg_Percentage from agg_user where year = {Year} and quarter = {Quarter} group by brands order by Total_Count desc limit 10")
df = pd.DataFrame(mycursor.fetchall(), columns=['Brand', 'Total_Users','Avg_Percentage'])
fig = px.bar(df,
title='Top 10',
x="Total_Users",
y="Brand",
orientation='h',
color='Avg_Percentage',
color_continuous_scale=px.colors.sequential.Agsunset)
st.plotly_chart(fig,use_container_width=True)
with col2:
st.markdown("### :violet[District]")
mycursor.execute(f"select district, sum(RegisteredUser) as Total_Users, sum(AppOpens) as Total_Appopens from map_user where year = {Year} and quarter = {Quarter} group by district order by Total_Users desc limit 10")
df = pd.DataFrame(mycursor.fetchall(), columns=['District', 'Total_Users','Total_Appopens'])
df.Total_Users = df.Total_Users.astype(float)
fig = px.bar(df,
title='Top 10',
x="Total_Users",
y="District",
orientation='h',
color='Total_Users',
color_continuous_scale=px.colors.sequential.Agsunset)
st.plotly_chart(fig,use_container_width=True)
with col3:
st.markdown("### :violet[Pincode]")
mycursor.execute(f"select Pincode, sum(RegisteredUsers) as Total_Users from top_user where year = {Year} and quarter = {Quarter} group by Pincode order by Total_Users desc limit 10")
df = pd.DataFrame(mycursor.fetchall(), columns=['Pincode', 'Total_Users'])
fig = px.pie(df,
values='Total_Users',
names='Pincode',
title='Top 10',
color_discrete_sequence=px.colors.sequential.Agsunset,
hover_data=['Total_Users'])
fig.update_traces(textposition='inside', textinfo='percent+label')
st.plotly_chart(fig,use_container_width=True)
with col4:
st.markdown("### :violet[State]")
mycursor.execute(f"select state, sum(Registereduser) as Total_Users, sum(AppOpens) as Total_Appopens from map_user where year = {Year} and quarter = {Quarter} group by state order by Total_Users desc limit 10")
df = pd.DataFrame(mycursor.fetchall(), columns=['State', 'Total_Users','Total_Appopens'])
fig = px.pie(df, values='Total_Users',
names='State',
title='Top 10',
color_discrete_sequence=px.colors.sequential.Agsunset,
hover_data=['Total_Appopens'],
labels={'Total_Appopens':'Total_Appopens'})
fig.update_traces(textposition='inside', textinfo='percent+label')
st.plotly_chart(fig,use_container_width=True)
# MENU 3 - EXPLORE DATA
if selected == "Explore Data":
Year = st.sidebar.slider("**Year**", min_value=2018, max_value=2022)
Quarter = st.sidebar.slider("Quarter", min_value=1, max_value=4)
Type = st.sidebar.selectbox("**Type**", ("Transactions", "Users"))
col1,col2 = st.columns(2)
# EXPLORE DATA - TRANSACTIONS
if Type == "Transactions":
# Overall State Data - TRANSACTIONS AMOUNT - INDIA MAP
with col1:
st.markdown("## :violet[Overall State Data - Transactions Amount]")
mycursor.execute(f"select state, sum(count) as Total_Transactions, sum(amount) as Total_amount from map_trans where year = {Year} and quarter = {Quarter} group by state order by state")
df1 = pd.DataFrame(mycursor.fetchall(),columns= ['State', 'Total_Transactions', 'Total_amount'])
df2 = pd.read_csv(r'D:\Dimpu\ProjectWorks\Python\PhonepePulseData\Data\Statenames.csv')
df1.State = df2
fig = px.choropleth(df1,geojson="https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson",
featureidkey='properties.ST_NM',
locations='State',
color='Total_amount',
color_continuous_scale='sunset')
fig.update_geos(fitbounds="locations", visible=False)
st.plotly_chart(fig,use_container_width=True)
# Overall State Data - TRANSACTIONS COUNT - INDIA MAP
with col2:
st.markdown("## :violet[Overall State Data - Transactions Count]")
mycursor.execute(f"select state, sum(count) as Total_Transactions, sum(amount) as Total_amount from map_trans where year = {Year} and quarter = {Quarter} group by state order by state")
df1 = pd.DataFrame(mycursor.fetchall(),columns= ['State', 'Total_Transactions', 'Total_amount'])
df2 = pd.read_csv(r'D:\Dimpu\ProjectWorks\Python\PhonepePulseData\Data\Statenames.csv')
df1.Total_Transactions = df1.Total_Transactions.astype(int)
df1.State = df2
fig = px.choropleth(df1,geojson="https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson",
featureidkey='properties.ST_NM',
locations='State',
color='Total_Transactions',
color_continuous_scale='sunset')
fig.update_geos(fitbounds="locations", visible=False)
st.plotly_chart(fig,use_container_width=True)
# BAR CHART - TOP PAYMENT TYPE
st.markdown("## :violet[Top Payment Type]")
mycursor.execute(f"select Transaction_type, sum(Transaction_count) as Total_Transactions, sum(Transaction_amount) as Total_amount from agg_trans where year= {Year} and quarter = {Quarter} group by transaction_type order by Transaction_type")
df = pd.DataFrame(mycursor.fetchall(), columns=['Transaction_type', 'Total_Transactions','Total_amount'])
fig = px.bar(df,
title='Transaction Types vs Total_Transactions',
x="Transaction_type",
y="Total_Transactions",
orientation='v',
color='Total_amount',
color_continuous_scale=px.colors.sequential.Agsunset)
st.plotly_chart(fig,use_container_width=False)
# BAR CHART TRANSACTIONS - DISTRICT WISE DATA
st.markdown("# ")
st.markdown("# ")
st.markdown("# ")
st.markdown("## :violet[Select any State to explore more]")
selected_state = st.selectbox("",
('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'),index=30)
mycursor.execute(f"select State, District,year,quarter, sum(count) as Total_Transactions, sum(amount) as Total_amount from map_trans where year = {Year} and quarter = {Quarter} and State = '{selected_state}' group by State, District,year,quarter order by state,district")
df1 = pd.DataFrame(mycursor.fetchall(), columns=['State','District','Year','Quarter',
'Total_Transactions','Total_amount'])
fig = px.bar(df1,
title=selected_state,
x="District",
y="Total_Transactions",
orientation='v',
color='Total_amount',
color_continuous_scale=px.colors.sequential.Agsunset)
st.plotly_chart(fig,use_container_width=True)
# EXPLORE DATA - USERS
if Type == "Users":
# Overall State Data - TOTAL APPOPENS - INDIA MAP
st.markdown("## :violet[Overall State Data - User App opening frequency]")
mycursor.execute(f"select state, sum(RegisteredUser) as Total_Users, sum(AppOpens) as Total_Appopens from map_user where year = {Year} and quarter = {Quarter} group by state order by state")
df1 = pd.DataFrame(mycursor.fetchall(), columns=['State', 'Total_Users','Total_Appopens'])
df2 = pd.read_csv(r'D:\Dimpu\ProjectWorks\Python\PhonepePulseData\Data\Statenames.csv')
df1.Total_Appopens = df1.Total_Appopens.astype(float)
df1.State = df2
# BAR CHART TOTAL UERS - DISTRICT WISE DATA
st.markdown("## :violet[Select any State to explore more]")
selected_state = st.selectbox("",
('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'),index=30)
mycursor.execute(f"select State,year,quarter,District,sum(Registereduser) as Total_Users, sum(AppOpens) as Total_Appopens from map_user where year = {Year} and quarter = {Quarter} and state = '{selected_state}' group by State, District,year,quarter order by state,district")
df = pd.DataFrame(mycursor.fetchall(), columns=['State','year', 'quarter', 'District', 'Total_Users','Total_Appopens'])
df.Total_Users = df.Total_Users.astype(int)
fig = px.bar(df,
title=selected_state,
x="District",
y="Total_Users",
orientation='v',
color='Total_Users',
color_continuous_scale=px.colors.sequential.Agsunset)
st.plotly_chart(fig,use_container_width=True)
# MENU 4 - ABOUT
if selected == "About":
col1,col2 = st.columns([6,1],gap="medium")
with col1:
st.write(" ")
st.write(" ")
st.markdown("### :violet[About PhonePe Pulse:] ")
st.write("##### On Sept. 3, 2021 PhonePe, India's leading fintech platform, announced the launch of PhonePe Pulse, India's first interactive website with data, insights and trends on digital payments in the country. The PhonePe Pulse website showcases more than 2000+ Crore transactions by consumers on an interactive map of India. With over 45% market share, PhonePe's data is representative of the country's digital payment habits.")
st.write("##### The insights on the website and in the report have been drawn from two key sources - the entirety of PhonePe's transaction data combined with merchant and customer interviews. The report is available as a free download on the PhonePe Pulse website and GitHub.")
st.markdown("### :violet[About PhonePe:] ")
st.write("##### PhonePe is India's leading fintech platform with over 300 million registered users. Using PhonePe, users can send and receive money, recharge mobile, DTH, pay at stores, make utility payments, buy gold and make investments. PhonePe forayed into financial services in 2017 with the launch of Gold providing users with a safe and convenient option to buy 24-karat gold securely on its platform. PhonePe has since launched several Mutual Funds and Insurance products like tax-saving funds, liquid funds, international travel insurance and Corona Care, a dedicated insurance product for the COVID-19 pandemic among others. PhonePe also launched its Switch platform in 2018, and today its customers can place orders on over 600 apps directly from within the PhonePe mobile app. PhonePe is accepted at 20+ million merchant outlets across Bharat")
st.write("**:violet[My Project GitHub link]** ⬇️")
st.write("https://github.com/pcden/https---github.com-pcden-Phonepepulsedata")
st.write("**:violet[Image and content source]** ⬇️")
st.write("https://www.prnewswire.com/in/news-releases/phonepe-launches-the-pulse-of-digital-payments-india-s-first-interactive-geospatial-website-888262738.html")
with col2:
st.write(" ")
st.write(" ")
st.write(" ")
st.write(" ")