I have a data frame like this:
df = pd.DataFrame({'x':[[0,0]], 'y':[[[1,3,5], [2,4,6]]]})
I'd like to split y
into 3 columns such as this:
x y_x y_y y_z
0 [0, 0] [1, 2] [3,4] [5, 6]
What's the best way to do this in pandas?
CodePudding user response:
You may check
out = df.join(df.y.apply(lambda x : pd.Series(zip(x[0],x[1]))))
Out[452]:
x y 0 1 2
0 [0, 0] [[1, 3, 5], [2, 4, 6]] (1, 2) (3, 4) (5, 6)