delete duplicate values concatenating the columns "Value2", "Value3" and "Value5" of dataframe "DF" for the columns "Value1" and "Value4" keep the first value add the Column "Counter" with the number of duplicated data
def concatenate_deduplicate(df, col_list): df_copy = df df_copy.loc[:, col_list] = df_copy.loc[:, col_list].astype(str).apply(lambda x: ','.join(x.drop_duplicates()), axis=1) df_copy.loc[:, 'Counter'] = df_copy.loc[:, col_list].apply(lambda x: x.count(',')+1) return df_copy