0

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]
8
  • 4
    What effort have you made so far? Commented Apr 18, 2016 at 16:10
  • What version of python? Commented Apr 18, 2016 at 16:12
  • map(lambda df: df.t > 2, dtList) should do Commented Apr 18, 2016 at 16:15
  • 1
    @BlackCat: Answers go in the answer section please mate. This isn't a chatroom or message board! Thanks Commented Apr 18, 2016 at 16:23
  • 1
    @IanS: Then he should leave the posting to someone who does! Comments cannot be reviewed, fully voted, edited, etc. This site has a very specific model and the technology that powers it works best when content is posted in the right place. Comments are for requesting clarification, and flame wars; that's it. :) Commented Apr 18, 2016 at 16:35

1 Answer 1

3

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]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.