I have a pandas dataframe named Incoming_Tags
I can do groupby
on the dataframe by mentioning the column names as input to groupby:
Example:
Incoming_Tags.groupby([ 'Domain','Tag_Name', 'Tag_hierarchy', 'html_attributes'])
I want to select columns dynamically for doing groupby
.
Dynamically means by names. Instead of mentioning the columns names each time in groupby
. I have defined a function group_by
, which does the following:
def group_by(df,myList= [],*args):
Incoming_tag_groupby = df.groupby(myList).agg({'char_cnt': np.mean,'line_cnt':np.mean,'digit_cnt':np.mean,'sp_chr_cnt':np.mean,'word_cnt':np.mean})
return Incoming_tag_groupby