嗨,我有以下数据框
Name Age Height Country
Jack 18 185 AU
Jill 16 159 NZ
Geoff 16 177 US
Tess 15 155 AU
我试图找到一个特定的行,然后定义两个变量以在其他计算中使用。
例如,我想知道 Geoff
的高度和国家/地区
名称 = '杰夫'
h = 177
c=美国
有谁知道搜索和查找此内容的最有效方法?谢谢!
最佳答案
或者,您也可以使用 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']
关于python - 将特定单元格定义为 pandas 数据框中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65101120/