1

I have a dataframe where I have performed operation like:

  df: 

      ColA      ColB       ColC 
      1         7.9E-08    1.3E-16
      0.92      2.2E-02    4.5E-18
      0.98      2.2E-06    5.6E-18

I want to check if value of colA is > 0.95, If yes, I want to print true in additional column or 'False' if not

The output should looks like:

  ColA      ColB       ColC     Confidence %
  1         7.9E-08    1.3E-16   True
  0.92   2.2E-02    4.5E-18      False
  0.98   2.2E-02    4.5E-18      Type

Code:

for index, row in result_withoutTC.iterrows():
    if row['Confidence %'] > 0.95:
        reject_list.append(True)

    else:
        accept_list_withoutTC.append(False)

result_withoutTC['Confidence %'] = reject_list_without_TC
Tjs01
  • 457
  • 2
  • 8
  • 14
  • [Possible duplicate, although I think this is simple and unique enough](https://stackoverflow.com/q/33695769/4435344), Cheers. Difference is a logical operator change. – akozi Dec 20 '18 at 14:42

2 Answers2

3

For a simple test of this sort you can create this column directly with:

result_withoutTC['confidence'] = result_withoutTC['ColA']>0.95
Joe Halliwell
  • 1,155
  • 6
  • 21
1

There's a lot of way to do it... for example using a numpy function np.where

df['Confidence %'] = np.where(df.ColA > 0.95,True,False)

Or using a pandas function mask

df['Confidence %'] = True
df['Confidence %'] = df['Confidence %'].mask(df.ColA < 0.95,False)

Both with a result of:

   ColA          ColB          ColC  Confidence %
0  1.00  7.900000e-08  1.300000e-16          True
1  0.92  2.200000e-02  4.500000e-18         False
2  0.98  2.200000e-06  5.600000e-18          True