Generation

generate functionTue, 24 Jan 2023

Write a pandas function that groups matching columns traffic_source and region and outputs the values of the third column source_type for them

def merge_cols(df, col_list): return df.groupby(col_list)[['source_type']].apply(lambda x: tuple(x)).reset_index(name='source_type') merge_cols(df, ['traffic_source', 'region'])

Questions about programming?Chat with your personal AI assistant