1

I have a data frame looks as follows

df1 = df = pd.DataFrame({"a":[[{"x":0,"y":4}], None, [{"x":10,"y":5}], None], 
                     "b":[5, 6, 7, 8]}) 

How can create a seperate column of x and y from it ?

0

1 Answer 1

2

You can do:

df[['x', 'y']] = df['a'].str[0].apply(pd.Series)

print(df)

                     a  b     x    y
0   [{'x': 0, 'y': 4}]  5   0.0  4.0
1                 None  6   NaN  NaN
2  [{'x': 10, 'y': 5}]  7  10.0  5.0
3                 None  8   NaN  NaN
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.