I have a question regarding splitting a list in a dataframe column into multiple rows.
Let's say I have this dataframe:
Job position Job type id
0 [6] [1] 3
1 [2, 6] [3, 6, 5] 4
2 [1] [9] 43
I would like every single combination of numbers, so the final result would be:
id Job position Job type
0 3 6.0 1.0
1 4 2.0 3.0
2 4 2.0 6.0
3 4 2.0 5.0
4 4 6.0 3.0
5 4 6.0 6.0
6 4 6.0 5.0
7 43 1.0 9.0
Because right now I get this result:
id Job position Job type
0 3 6.0 1.0
1 4 2.0 3.0
2 4 6.0 6.0
3 4 NaN 5.0
4 43 1.0 9.0
In order to get the result above, I did:
df = df.set_index(['id'])
(df.apply(lambda x: pd.DataFrame(x.tolist(),index=x.index)
.stack()
.rename(x.name)).reset_index())