Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create Boolean column with values opposite to another

Be the following DataFrame in pandas:

Column_1 Column_2 Column_3 Column_4 Column_5 New_column
82198 True False False red True
27498 False False False red False
84838 False False True red True
10498 False True False red True

I want to add another New_column_2 with the opposite values to New_column:

Column_1 Column_2 Column_3 Column_4 Column_5 New_column New_column_2
82198 True False False red True False
27498 False False False red False True
84838 False False True red True False
10498 False True False red True False

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

A possible solution:

df['New_column_2'] = ~df['New_column']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading