Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

python - Pandas: `item` has been deprecated

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 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']

I expected a single integer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could also just use .iloc[0], but keep in mind that it will raise an IndexError if there is not at least one item in the series you're calling it on.

s = event_data.loc[event_data.event_id == event_id, 'max_total_gross']
s.iloc[0]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...