Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 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 Answer

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...