You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Pandas中查找年龄为81岁的糖尿病患者完整数据?

解决方法
  • 报错原因是diabet[age_max]是按列名索引数据,但81不是你的数据集列名,所以会出错。要查看81岁患者的其他属性,得用布尔索引筛选行:
    # 筛选所有年龄为81的患者数据
    max_age_patients = diabet[diabet['Age'] == age_max]
    print(max_age_patients)
    
  • 要是确定只有一位81岁患者,可直接提取单行数据:
    # 获取唯一的81岁患者数据
    single_patient = max_age_patients.iloc[0]
    print(single_patient)
    
  • 额外提一句:计算最大年龄不用先取unique(),直接用Pandas自带的max()方法更高效:
    age_max = diabet['Age'].max()
    

内容的提问来源于stack exchange,提问作者Sapphire Cantos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 03:50:59