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 = 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)
推荐阅读
- azure - Azure Service Fabric 群集的负载均衡器
- java - 生成令牌以访问邮递员的文档时出错
- nginx - 如何告诉 Kubernetes 在创建后不要立即向 Pod 发送流量
- c# - 序列化/反序列化嵌套的 POCO 属性,而不在 json.net 中嵌套
- azure - 名称中带有“@”的 SQL 登录(例如电子邮件)在 Azure SQL 托管实例中不起作用
- angular - 角度错误:未捕获(承诺):错误:无法匹配任何路由
- python - Keras Tuner:“最优”模型过拟合,搜索停止在极端超参数值处
- apache-flink - Flink:无法通过 Table API 创建 mysql JDBC 连接
- sass - SCSS 字体堆栈混合错误:“`map-get($map, $key)` 的参数 `$map` 必须是地图”
- javascript - 根据类名替换 HTML 元素?