Created
March 1, 2021 19:53
-
-
Save Abuton/9f20b871f7f6659e35249e16845853ee to your computer and use it in GitHub Desktop.
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
# function to calculate feature engineering by aggregating integer columns | |
def get_agg_by_cols(data, col, agg_list, agg_cols): | |
""" | |
data : dataframe to calculate FE on | |
col : list of columns to aggregate by (the object datatype) | |
agg_list : a list of statistical measure e.g mean, median | |
agg_cols : a list of numerical datatype columns | |
""" | |
for cols in col: | |
for i in agg_list: | |
for j in agg_cols: | |
data[cols+'_'+j+'_'+i] = data.groupby([cols])[j].transform(i) | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment