Concatenating equal data from a column into rows in Python

Asked

Viewed 487 times

2

Base de Dados

What I need is to find a function in Python that mounts my file this way. I already searched in pandas and did not find.

1 answer

2


One way is to:

df.groupby('Categoria').agg({'Descricao':lambda col: ', '.join(col)}).reset_index()

This way you are grouping the same data from the column Categoria and using for the column Descricao the rule lambda col: ', '.join(col), that is, concatenating the data into a string separated by ', '.

  • Thank you so much Alex ! Solved :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.