首页 > 解决方案 > 无法在 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 = 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

有人可以帮我吗?

标签: pythonpandas

解决方案


你几乎拥有它!以下应该给你你想要的:

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)

推荐阅读