Conditional Logic on Pandas DataFrame

后端 未结 4 573
遥遥无期
遥遥无期 2020-12-01 03:23

How to apply conditional logic to a Pandas DataFrame.

See DataFrame shown below,

   data desired_output
0     1          False
1     2          Fals         


        
4条回答
  •  情书的邮戳
    2020-12-01 04:20

    In this specific example, where the DataFrame is only one column, you can write this elegantly as:

    df['desired_output'] = df.le(2.5)
    

    le tests whether elements are less than or equal 2.5, similarly lt for less than, gt and ge.

提交回复
热议问题