Skip to content Skip to sidebar Skip to footer

Unnest (explode) Multiple List 2.0

Background The following code is modified from here Efficient way to unnest (explode) multiple list columns in a pandas DataFrame I create a dataframe import pandas as pd df = pd.

Solution 1:

Just fix your output by adding ffill

df.set_index('Ban').apply(lambda x: x.apply(pd.Series).stack()).groupby(level=0).ffill().reset_index(drop=True)
Out[794]: 
  Ban App   C   D   E
0  v1  x1  c2  d1  e1
1  v1  x1  c2  d2  e2
2  v2  x2  c3  d3  e3
3  v2  x2  c4  d4  e4
4  v3  x3  c5  d5  e5
5  v3  x3  c6  d6  e6
6  v4  x4  c7  d7  e7
7  v4  x4  c8  d8  e8

Post a Comment for "Unnest (explode) Multiple List 2.0"