0

I have a Pandas dataframe called 'df' that looks like this

Col1   TF      
1      False
2      True
2      False
2      False
2      False
3      False
4      False

And I would like for every row in to have a 'TF' value of True if Col1 = 2. The desired output for df is

Col1   TF      
1      False
2      True
2      True
2      True
2      True
3      False
4      False

I haven't found a method that works for me yet

1 Answers1

2

You could use numpy.where to check Col1 and modify the TF column:

df.TF = np.where(df.Col1 == 2, True, False)
fsl
  • 3,250
  • 1
  • 10
  • 20
Jose Avila
  • 191
  • 5
  • 4
    Welcome to SO, Jose. If you put four spaces before text, it will be formatted as code (https://stackoverflow.com/editing-help) – Ben Jones Oct 25 '19 at 21:23