Getting a tuple in a Dafaframe into multiple rows
<p>I have a Dataframe, which has two columns (Customer, Transactions).
The  Transactions column is a tuple of all the transaction id's of that customer.</p>

<pre><code>Customer Transactions
1        (a,b,c)
2        (d,e)
</code></pre>

<p>I want to convert this into a dataframe, which has customer and transaction id's, like this.</p>

<pre><code>Customer  Transactions
1         a
1         b
1         c
2         d
2         e
</code></pre>

<p>We can do it using loops,  but is there a straight 1 or 2 lines way for doing that.</p>

<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html" rel="nofollow"><code>DataFrame</code></a> constructor:</p>

<pre><code>df = pd.DataFrame({'Customer':[1,2],
                   'Transactions':[('a','b','c'),('d','e')]})

print (df)
   Customer Transactions
0         1    (a, b, c)
1         2       (d, e)

df1 = pd.DataFrame(df.Transactions.values.tolist(), index=df.Customer)
print (df1)
          0  1     2
Customer            
1         a  b     c
2         d  e  None
</code></pre>

<p>Then reshape with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.stack.html" rel="nofollow"><code>stack</code></a>:</p>

<pre><code>print (df1.stack().reset_index(drop=True, level=1).reset_index(name='Transactions'))
   Customer Transactions
0         1            a
1         1            b
2         1            c
3         2            d
4         2            e
</code></pre>

python pandas dataframe tuples reshape