This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| best_churn["scaled_tran"] = (best_churn["no_of_transactions"] - best_churn["no_of_transactions"].min())/ (best_churn["no_of_transactions"].max() - best_churn["no_of_transactions"].min()) | |
| best_churn["scaled_amount"] = (best_churn["amount_spent"] -best_churn["amount_spent"].min()) / (best_churn["amount_spent"].max() - best_churn["amount_spent"].min()) | |
| best_churn["score"] = 100*(.5*best_churn["scaled_tran"] + .5*best_churn["scaled_amount"]) | |
| best_churn.sort_values("score", inplace=True, ascending=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| best_churn = pd.DataFrame(last_transaction) | |
| #Convert the cutoff_day to date time format | |
| cutoff_day = pd.to_datetime("01/05/20") | |
| def d(date): | |
| if date < cutoff_day: | |
| return 1 | |
| else: | |
| return 0 | |
| # Creating a boolean column to denote churn status | |
| best_churn["churned"] = best_churn["transaction_date"].apply(d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def standard_deviation(array): | |
| mean = sum(array) / len(array) | |
| distances = [] | |
| for value in array: | |
| # appending square of distances | |
| distances.append(((value - mean)**2)) | |
| return sum(distances) / len(distances) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def variance(array): | |
| mean = sum(array) / len(array) | |
| distances = [] | |
| for value in array: | |
| # appending square of distances | |
| distances.append(((value - mean)**2)) | |
| return sum(distances) / len(distances) | |
| input = [1,1,1,1,1,1,1,1,1,21] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def visualize_emoji(data): | |
| total_emojis_list = list([a for b in messages_df.emoji for a in b]) | |
| emoji_dict = dict(Counter(total_emojis_list)) | |
| emoji_dict = sorted(emoji_dict.items(), key=lambda x: x[1], reverse=True) | |
| emoji_df = pd.DataFrame(emoji_dict, columns=['emoji', 'count']) | |
| fig = px.pie(emoji_df, values='count', names='emoji') | |
| fig.update_traces(textposition='inside', textinfo='percent+label') | |
| fig.update_layout( | |
| margin=dict( | |
| l=5, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| st.title('Whatsapp Group Chat Analysis') | |
| st.markdown('Analysis on Exported chats to understand texting patterns of users.') | |
| st.set_option('deprecation.showfileUploaderEncoding', False) | |
| st.sidebar.title("Analyze:") | |
| st.sidebar.markdown("This app is use to analyze your WhatsApp Group Chats") | |
| st.sidebar.markdown('[![Saiteja Kura]\ | |
| (https://img.shields.io/badge/Author-@SaitejaKura-gray.svg?colorA=gray&colorB=dodgerblue&logo=github)]\ | |
| (https://github.com/kurasaiteja/Whatsapp-Analysis/)') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fig = go.Figure() | |
| fig.add_trace(go.Bar( | |
| x=columns, | |
| y=averages_AP, | |
| name="AP", | |
| marker_color='indianred' | |
| )) | |
| fig.add_trace(go.Bar( | |
| x=columns, | |
| y=averages_Telangana, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fig = go.Figure() | |
| fig.add_trace(go.Scatter( | |
| x=[lockdown1,lockdown2,lockdown3,lockdown4,unlock1,unlock2], | |
| y=[39,39,39,39,39,39], | |
| text=["Lockdown 1","Lockdown 2","Lockdown 3", "Lockdown 4", "Unlock 1", "Unlock 2"], | |
| mode="text", | |
| )) | |
| l = df_india_Telangana.columns |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| columns = ["Recreation","Grocery_and_Pharmacy","Parks","Transit_stations","Workplaces","Residential"] | |
| for i in columns: | |
| fig = px.box(df_india_Telangana_and_AP, x="Lockdown", y=i, color="State",width=600,height=400,title=i,template="plotly_dark")# or "inclusive", or "linear" by default | |
| fig.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def datephase(date): | |
| if date < "2020-03-22": | |
| return "Pre Lockdown" | |
| elif date < "2020-04-15": | |
| return "Lockdown Phase 1" | |
| elif date < "2020-05-04": | |
| return "Lockdown Phase 2" | |
| elif date < "2020-05-18": | |
| return "Lockdown Phase 3" | |
| elif date < "2020-06-01": |