Created
May 18, 2020 08:10
-
-
Save Alakhator/dda94e03609a7d7b31b3bc924c40952f to your computer and use it in GitHub Desktop.
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
train["User_ID_MeanPrice"] = train.groupby(['User_ID'])['Purchase'].transform('mean') | |
userID_mean_dict = train.groupby(['User_ID'])['Purchase'].mean().to_dict() | |
test['User_ID_MeanPrice'] = test['User_ID'].apply(lambda x:userID_mean_dict.get(x,0)) | |
train["Product_ID_MeanPrice"] = train.groupby(['Product_ID'])['Purchase'].transform('mean') | |
productID_mean_dict = train.groupby(['Product_ID'])['Purchase'].mean().to_dict() | |
test['Product_ID_MeanPrice'] = test['Product_ID'].apply(lambda x:productID_mean_dict.get(x,0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment