Create Boolean column with values opposite to another

Question:

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
Asked By: Carola

||

Answers:

A possible solution:

df['New_column_2'] = ~df['New_column']
Answered By: PaulS

did you try:

df['new_column2'] = ~df['new_column']
Answered By: Der Esel
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.