python - 如何获得 DF 的单个值
问题描述
我有以下情况:
id=id["ID"]
print(id)
结果:
0 7161 <br>Name: ID, dtype: int64
我只需要:
7161
怎么做?
id["ID"]
- 是过滤数据框的结果,并且始终只包含 1 条记录。
我如何尝试使用它:
#Identifying 客户列表仅限于“1”个记录,在特定时间范围内在商店中完成最高运行。
id = calc.most_value(df_orders,1)
#获取用户注册月度订单等的统计信息。
order_history_month = calc.client_stats(id,df_orders)
错误
Traceback (most recent call last):
File "/Users/sebastianhaja/PycharmProjects/nbn-poc/main.py", line 58, in <module>
order_history_month = calc.client_stats(id["ID"],df_orders)
File "/Users/sebastianhaja/PycharmProjects/nbn-poc/calc.py", line 59, in client_stats
result = orders[orders["member_id"]==id]
File "/Users/xxx/PycharmProjects/c24-/venv/lib/python3.9/site-packages/pandas/core/ops/common.py", line 65, in new_method
return method(self, other)
File "/Users/xxx/PycharmProjects/c24-/venv/lib/python3.9/site-packages/pandas/core/arraylike.py", line 29, in __eq__
return self._cmp_method(other, operator.eq)
File "/Users/xxx/PycharmProjects/c24-/venv/lib/python3.9/site-packages/pandas/core/series.py", line 4973, in _cmp_method
raise ValueError("Can only compare identically-labeled Series objects")
ValueError: Can only compare identically-labeled Series objects
谢谢你的帮助
塞布
解决方案
您可以使用iloc
或iat
:
>>> id["ID"].iloc[0]
推荐阅读
- azure - 我们可以在导入 API Azure 函数时在 Azure API 管理中添加默认值吗
- jqgrid - 如何在 jQGrid 中获取隐藏列
- powershell - 从xml计算foreach中的空元素
- javascript - 将数组的最后一个元素复制到不同的位置,然后将其从数组的末尾移除
- python - 如何将包含elemet字符串的列表转换为python中的列表
- javascript - 如何在 Angular Firestore 中使用 Firestore 管理用户存在
- jenkins - 没有代理的詹金斯动态阶段
- git - 在公司(经过身份验证的)代理后面使用 git lfs (Azure DevOps) 时遇到“需要身份验证”错误
- javascript - 使用 Vanilla JS 查找和替换具有某种颜色的所有元素的最佳方法是什么?
- image - 哪种颜色空间最适合颜色转换,为什么?