将特定单元格定义为数据帧中的变量

2024-06-07 11:36:31 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我有下面的数据框

Name    Age    Height    Country
Jack    18      185       AU
Jill    16      159       NZ
Geoff   16      177       US
Tess    15      155       AU

我试图找到一个特定的行,然后定义两个用于其他计算的变量

例如,我想知道Geoff的高度和国家

name = 'Geoff'h = 177c= US

有人知道最有效的搜索和澄清方法吗?谢谢


Tags: 数据nameage高度定义国家countryau
2条回答

或者,也可以使用df.query

df.query('Name == "Geoff"') # To get an entire row based on the filter condition
df.query('Name == "Geoff"').Height # For a specific column value (Height in this case) based on the filter
# or
df.query('Name == "Geoff"')['Height']

可以使用df.loc冻结整行

例如:

df.loc[df['Name'] == "Geoff"].Height

相关问题 更多 >

    热门问题