【发布时间】:2021-09-30 09:49:15
【问题描述】:
我是一名 Python 初学者,我想构建一个计算特定指标的 Python 函数,
例如,数据如下:
ID status Age Gender
01 healthy 16 Male
02 un_healthy 14 Female
03 un_healthy 22 Male
04 healthy 12 Female
05 healthy 33 Female
构建一个通过health+un_health计算健康人百分比的函数
def health_rate(healthy, un_healthy,age){
if (age >= 15):
if (gender == "Male"):
return rateMale= (count(healthy)/count(healthy)+count(un_healthy))
Else
return rateFemale= (count(healthy)/count(healthy)+count(un_healthy))
Else
return print("underage");
然后只需使用 .apply
但逻辑不对,我仍然没有得到我想要的输出 我要返回男价和女价
【问题讨论】:
标签: python dataframe indicator