My issue is the following
I have the following sample data.
| UserId | OriginLink |
|---|---|
| A | potato |
| B | |
| A | apple |
| B |
When i run the following line of code.
prod.groupby(['UserId'])['OriginLink'].apply(lambda d : list(d)).reset_index()
I get the following result:
| UserId | OriginLink |
|---|---|
| A | [potato,apple] |
| B | [,,] |
How can i guarantee that it doesn return the empty list in the B row. I tried a few if statement, but it didnt work
Wanted result
| UserId | OriginLink |
|---|---|
| A | [potato,apple] |
>Solution :
You can use a dropna if you want to drop anything that is null
prod.dropna(inplace = True)
prod.groupby(['UserId'])['OriginLink'].apply(lambda d : list(d)).reset_index()