首页 > 解决方案 > 如何获得 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

谢谢你的帮助

塞布

标签: pythonpandas

解决方案


您可以使用ilociat

>>> id["ID"].iloc[0]

推荐阅读