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.
append was deprecated because: "Series. append and DataFrame. append [are] making an analogy to list. append, but it's a poor analogy since the behavior isn't (and can't be) in place.
We can use pd. __version__ to check the version of the Pandas running on any system.
In order to convert data types in pandas, there are three basic options: Use astype() to force an appropriate dtype. Create a custom function to convert the data. Use pandas functions such as to_numeric() or to_datetime()
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]
The method item()
is still useful if you want to assert that the Series has length exactly 1, and also get that single value at the same time. I recommend replacing:
result = ser.item()
with:
result = ser.values.item()
which should do what you want.
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)
It has been undeprecated again in pandas 1.0 for exactly this use case:
Series.item() and Index.item() have been undeprecated (GH29250)
from https://pandas.pydata.org/docs/whatsnew/v1.0.0.html#deprecations. See also discussion in the issue GH29250.
So consider updating or ignoring or silencing the warning instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With