0

Say I have the following:

                   X         Y  
A    B                          
bar  one    0.094315 -0.816244  
     three -1.316294 -0.383182  
flux six   -0.176711  0.117511  
     three -1.401581  1.471682  
foo  five   0.647646 -0.422405  
     one   -0.319071  1.598857  
     two   -0.234279  0.082658  
     two    0.423970  1.418249  

and that I get some boolean Series indexing my Dataframe, e.g. my_series = df['X'] > 0.

I would like use this my_series to fill-in specific entries on column Y. I could certainly do:

df[my_series]['Y'] = 1

but this would write on a view. How can I combine boolean-based indexing with regular label indexing?

1 Answer 1

4

Use df.loc[df.X > 0, 'Y'] = 1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.