python - 无法选择 Pandas 中的单元格

标签 python pandas

这可能是一件非常愚蠢的事情,但我真的对此感到生气。 假设我有以下数据框(表格实际上要大得多,但这并不重要):

Index   Call Rate   Array Info.X    Array Info.Y
    0   "0.993922"  20202821    R01C01
    1   "0.723922"  20217347    R01C01
    2   "0.493922"  20257906    R01C01
    3   "0.723922"  20355030    R01C01

我正在尝试使用以下代码来提取组合“20257906”(文件夹)和 R01C01(current_section)的值“Call Rate”。

call_rate = samples_table.loc[((samples_table['Array Info.Y'] == current_section))]# & (samples_table['Array Info.X'] == (f"{folder}")),'Call Rate']
call_rate = float(numpy.round(call_rate, decimals=4))

但是,变量 call_rate 似乎为空,因此无需舍入。 该信息在数据框中正确存在,因此我认为这是由代码第一行中的错误引起的。

我正在使用 Spyder,变量资源管理器将变量“call_rate”描述为:

Series; (0,); Series of pandas.core.series module

有人可以帮我吗?

最佳答案

你几乎已经拥有它了!以下内容应该可以满足您的需求:

current_section = 'R01C01'
folder = 20257906

call_rate = samples_table[(samples_table['Array Info.X'] == folder) & (df['Array Info.Y'] == current_section)]['Call Rate']

call_rate = np.round(float(call_rate.iloc[0]), decimals=4)

关于python - 无法选择 Pandas 中的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60317935/

相关文章:

python - 谷歌历史价格到 Pandas 数据框

python - 将元组分配给 pandas 数据帧的多个元素

python - 如何将多个 Unix 时间戳转换为 Pandas 日期时间?

python - py.test : error: unrecognized arguments: --cov-report --cov=

python - 在 Python 中分析内存分配(支持 Numpy 数组)

python - Pandas key 错误 : 'occurred at index 0'

python - 在 Python 中实现 Adams Bashforth Moulton 方法

python - 决策树 Sklearn - 树的深度和准确性

python - 如何选择根据 pandas 中的前一行和下一行条件过滤的行并将它们放入空 df 中?

Python Pandas key 错误 : 'the label is not in the [index]'