python split data frame columns into multiple rows
<p>I have a dataframe like this:</p>

<pre><code>--------------------------------------------------------------------
Product        ProductType     SKU                Size
--------------------------------------------------------------------
T-shirt        Top            [111,222,333,444]   ['XS','S','M','L']
Pant(Flared)   Bottoms        [555,666]           ['M','L']
Sweater        Top            None                None
</code></pre>

<p>I want the below output:</p>

<pre><code>Product       ProductType        SKU        Size
T-shirt       Top                111        XS
T-shirt       Top                222        S
T-shirt       Top                333        M
T-shirt       Top                444        L
Pant(Flared)  Bottoms            555        M
Pant(Flared)  Bottoms            666        L
Sweater       Top                None       None
</code></pre>

<p>I tried the following code:</p>

<pre><code>s = df['SKU'].apply(Series,1).stack()
s.index = s.index.droplevel(-1)
s.name = 'SKU'
del df['SKU']
df = df.join(s)

r = df['Size'].apply(Series,1).stack()
r.index = r.index.droplevel(-1)
r.name = 'Size'
del df['Size']
df = df.join(r)
</code></pre>

<p>But this explodes into the following:</p>

<pre><code>Product       ProductType   SKU             Size
T-shirt       Top           111             XS
T-shirt       Top           111             S
T-shirt       Top           111             M
T-shirt       Top           111             L
T-shirt       Top           222             XS
T-shirt       Top           222             S
T-shirt       Top           222             M
T-shirt       Top           222             L
T-shirt       Top           333             XS
T-shirt       Top           333             S
T-shirt       Top           333             M
T-shirt       Top           333             L
T-shirt       Top           444             XS
T-shirt       Top           444             S
T-shirt       Top           444             M
T-shirt       Top           444             L
Pant(Flared)  Bottoms       555             M
Pant(Flared)  Bottoms       555             L
Pant(Flared)  Bottoms       666             M
Pant(Flared)  Bottoms       666             L
</code></pre>

<p>Note that for simplicity sake, I have added two columns that will be repeated (Product, ProductType) but I have 5 such columns that contain strings.
I basically want to associate the SKU with the size for each product.</p>

<p>Can anyone help here ?</p>