I have this dataframe :
| ID | x | y | z |
|---|---|---|---|
| 1 | new york | california | |
| 2 | vermont; new york | carolina n | florida |
| 2 | oregon | texas | florida; colorado |
| 3 | new jersey | ||
| 1 | hawai | utah |
I'm trying to group by ID, and merge column x, y, and z into one column.
Output should be :
| ID | geo |
|---|---|
| 1 | new york; california; hawai; utah |
| 2 | vermont; new york; carolina n; oregon; texas; florida; colorado; florida |
| 3 | new jersey |
I tried with the following piece of code :
save = df.groupby('ID').agg(lambda x: ';'.join(set(x)))
But it doesn't work.