Dataframe grouping problem

clipboard.png
when grouping in the first step, I want to take only the top 10 of each group for mean and sun operations

Aug.17,2021

    http_df.sort_values(['dst_ip', 'req_hdr_l'], ascending=[1, 0], inplace=True)
    tmp_df = http_df[['dst_ip', 'req_hdr_l']].groupby(['dst_ip']).head(20).groupby(['dst_ip'])['req_hdr_l'].agg(['mean', 'sum']).reset_index()
    tmp_df.columns = ['dst_ip', 'req_hdr_l_stats_[av/dst]', 'req hdr_l_stats[sum/dst]']
    http_df = pd.merge(tmp_df, http_df, how='right', on='dst_ip')
    
Menu