pandas :`item`已被弃用 [英] Pandas: `item` has been deprecated
本文介绍了 pandas :`item`已被弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,我在这里使用了以下代码行:
So far I used this line of code here:
max_total_gross = event_data["max_total_gross"].loc[event_data["event_id"] == event_id].item()
自从我更新熊猫以来,我收到未来的警告:
Since I updated Pandas I receive the future warning:
/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:12: FutureWarning:已弃用
item
,并将在 sys.path [0] ==''的将来版本:
/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:12: FutureWarning:
item
has been deprecated and will be removed in a future version if sys.path[0] == '':
我试图用这种方式修复它,但是结果不一样:
I tried to fix it that way, but it's not the same outcome:
event_data.loc[event_data.event_id == event_id, 'max_total_gross']
我希望有一个整数.
推荐答案
如果需要第一个匹配的值,请将iter
与next
一起使用,优点是如果没有匹配的值则返回默认值:
If need first matched value use iter
with next
, advantage is if no value is matched is returned default value:
s = event_data.loc[event_data.event_id == event_id, 'max_total_gross']
out = next(iter(s), 'no match')
print (out)
这篇关于 pandas :`item`已被弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文