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
1

2 Answers 2

3

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

result_withoutTC['confidence'] = result_withoutTC['ColA']>0.95
Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

Your numpy solution is nice, although I think @JoeHalliwell's pandas solution makes more sense.
And simple.. just giving you different options!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.