mardi 12 février 2019

How can I add some IF statements with decimal variables?

I have a variable X which contains a decimal value. I want to write some IF conditions to match X to a dataframe.

Say I have X = 1.1 and a dataframe called OutputDF as below.

OutputDF
   score    ID
1    32     1.2
2    35     1.3
3    20     2.1
4    15     3.2      

I want to write some IF conditions that works on decimals.

I want to include 3 conditions regarding this output.

C1. If 1.x is the only element print YES. In the above output we can see that 1.x is not the only element. There is 2.x and 3.x there as well.

C2. If 1.x is not the only element but 1.x has highest score print YES. In the sample we can see a 1.x contains highest score so this time it is a yes.

C3. If 1.x is not the only element but 1.x occurs most frequent print YES. In the sample we can see that 1.x occurs 2 times vs the other elements so it is a yes.

So my expected output for the above sample is

ID  C1   C2   C3
1.1 NO   YES  YES

Aucun commentaire:

Enregistrer un commentaire