COUNTIF in pandas python over multiple columns with multiple conditions

前端 未结 3 519
旧时难觅i
旧时难觅i 2020-12-06 06:58

I have a dataset wherein I am trying to determine the number of risk factors per person. So I have the following data:

Person_ID  Age  Smoker  Diabetes
              


        
3条回答
  •  囚心锁ツ
    2020-12-06 07:34

    If you are starting from excel and want to go to the next evolution then I would recommend MS access. It will be a lot easier then learning Panda for python. You should just replace the CountIf() with:

    Risk Factor: IIF(Age>45, 1, 0) + IIF(Smoker="Y", 1, 0) + IIF(Diabetes="Y", 1, 0)

提交回复
热议问题