python - 将特定单元格定义为 pandas 数据框中的变量

标签 python pandas

嗨,我有以下数据框

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/

相关文章:

python - 在 Python 中处理字节和二进制数据

python - 旧版本 python 的 OrderedDict

python - 使用 Pandas Dataframe 仅选择一个日期小于另一个日期的行

python - pip 无法安装 PIL 或 Pillow 并出现 mt.exe 错误

python - 通过代理IP连接Flask localhost服务器

python - 颜色条刻度标签作为日志输出

python - 如何将 lambda 函数应用于 pandas 数据框中的时间戳列

python - 如何根据 Pandas 中的条件将一个数据帧中缺失的行添加到另一个数据帧?

python - 使用 isin 函数后,我不能在 pandas Dataframe 上使用 filter 函数是有原因的吗?

python - to_excel() 没有索引布局