This file contains 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 pandas as pd | |
dau = pd.read_csv("section3-dau.csv", parse_dates=['log_date']) | |
dpu = pd.read_csv("section3-dpu.csv", parse_dates=['log_date']) | |
install = pd.read_csv("section3-install.csv", parse_dates=['install_date']) |
This file contains 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
# dauとインストール情報を結合させる | |
dau_install = pd.merge(dau, install, on=['app_name', 'user_id']) | |
# 上記の情報に、課金情報を結合させる | |
user_info = pd.merge(dau_install, dpu, on=['log_date', 'app_name', 'user_id'], how='left').fillna(0) |
This file contains 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
# 年月の単位の列を追加する | |
user_info['log_month'] = user_info['log_date'].apply(lambda x: str(x)[0:7]) | |
user_info['install_month'] = user_info['install_date'].apply(lambda x: str(x)[0:7]) |
This file contains 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
# アクセスした年月の列を追加 | |
user_info['log_month'] = user_info['log_date'].apply(lambda x: str(x)[0:7]) | |
# インストールした年月の列を追加 | |
user_info['install_month'] = user_info['install_date'].apply(lambda x: str(x)[0:7]) |
This file contains 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
user_info['new_user'] = user_info['log_month'] == user_info['install_month'] |
This file contains 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
user_info.groupby(['app_name', 'log_month', 'new_user'])['payment'].sum().unstack() |
This file contains 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
user_info.groupby(['app_name', 'log_month', 'new_user'])['payment'].sum().unstack().plot(kin | |
d='bar', stacked=True) |
This file contains 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
purchasers = user_info[user_info['payment'] > 0] |
This file contains 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
purchasers.groupby(['app_name', 'log_month', 'user_id'])['payment'].sum().apply(lambda x: int(x) / 2000 * 2000) |
This file contains 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
payment_info = purchasers.groupby(['app_name', 'log_month', 'user_id'], as_index=False)['payment'].sum() | |
payment_info['payment_band'] = payment_info['payment'].apply(lambda x: int(x) / 2000 * 2000) |
OlderNewer