I have following situation:
id=id["ID"] print(id)
Result:
0 7161
Name: ID, dtype: int64
And I need just:
7161
How to do it?
id["ID"] - is a result of filtering data frame and always include only 1 record.
How I am trying to use it:
#Identifying client list limited to "1" record with done highest run-over on the shop with certain time scales.
id = calc.most_value(df_orders,1)
#Getting stats for user reg monthly orders etc.
order_history_month = calc.client_stats(id,df_orders)
ERROR
Traceback (most recent call last): File "/Users/sebastianhaja/PycharmProjects/nbn-poc/main.py", line 58, in 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
Thank you for Help
Seb
CodePudding user response:
You can use iloc
or iat
:
>>> id["ID"].iloc[0]
CodePudding user response:
Use:
new=id["ID"].iat[0]
new=id["ID"].to_numpy()[0]
new=id["ID"].tolist()[0]
If possible not match use iter
with next
trick:
new = next(iter(id["ID"]), 'no match')