peterchen
peterchen

Reputation: 97

If statement on Python

I have a dataframe like this:

block_id   number_repair  t    lognum                           
2              1.666667  1.0  0.462098
4              4.500000  2.5  1.468807
5              2.750000  1.5  0.895880
7              1.250000  1.5  0.173287
8              4.833333  2.5  1.297204

I would like to generate a respective list of 'True' or 'False' value. If 't' > 2 then return 'true', else return 'false'. How should I write the code to return result like the below?

[false true false false true]

Upvotes: 0

Views: 66

Answers (1)

jezrael
jezrael

Reputation: 863511

You can use tolist:

print df.t > 2
0    False
1     True
2    False
3    False
4     True
Name: t, dtype: bool

print (df.t > 2).tolist()
[False, True, False, False, True]

Upvotes: 3

Related Questions