How to convert column with list of values into rows in Pandas DataFrame
<p>Hi I have a dataframe like this:</p>

<pre><code>    A             B 
0:  some value    [[L1, L2]]
</code></pre>

<p>I want to change it into:</p>

<pre><code>    A             B 
0:  some value    L1
1:  some value    L2
</code></pre>

<p>How can I do that?</p>

<p>I can't find a elegant way to handle this, but the following codes can work...</p>

<pre><code>import pandas as pd
import numpy as np
df = pd.DataFrame([{"a":1,"b":[[1,2]]},{"a":4, "b":[[3,4,5]]}])
z = []
for k,row in df.iterrows():
    for j in list(np.array(row.b).flat):
        z.append({'a':row.a, 'b':j})
result = pd.DataFrame(z)
</code></pre>

python pandas dataframe