I am trying to group-by the values in my \"value_1\" column. But my last column is made up of lists. When I try to group-by using my \"value_1\" column, the column made up o
You could groupby value_1
and aggregate the columns containing strings with the following function:
def str_cat(x):
return x.str.cat(sep=', ')
And use GroupBy.sum to append the lists in the column list
:
df.replace('',None).groupby('value_1').agg({'list':'sum', 'value_2': str_cat,
'value_3': str_cat})
list value_2 \
value_1
american [supermarket, connivence, state] california, nyc, texas
canadian [coffee, sipermarket] toronto, texas
value_3
value_1
american walmart, kmart, dunkinDonuts
canadian dunkinDonuts, walmart