Skip to content Skip to sidebar Skip to footer

How To Convert 2d Into Row

I have a data-frame like: a b [[35.6113, -95.855]] [[[36.028, -95.93], [36.10, -95.82] .... ]]] How can i convert it into like

Solution 1:

Check with

s=pd.DataFrame({'a':df.a.repeat(df.b.str.len()),'b':sum(df.b.tolist(),[])})
s.apply(lambda x : x.str[0])

Out[104]: 
                    a                   b
0  [35.6113, -95.855]  [35.6113, -95.855]
0  [35.6113, -95.855]  [35.6113, -95.855]

Solution 2:

If using tuple doesn't limit you, you can solve this with:

s = pd.Series([tuple(x) for x in a])

Post a Comment for "How To Convert 2d Into Row"