Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) [duplicate]

I've recently upgraded Python to 3.7.6 and my existing code:

df['Simple_Avg_Return'] = df.groupby(['YF_Ticker'])['Share_Price_Delta_Percent', 'Dividend_Percent'].transform(
        sum).divide(2).round(2) 

Is now throwing this warning:

FutureWarning: Indexing with multiple keys (implicitly converted to a
tuple of keys) will be deprecated, use a list instead.  

How would I go about converting this to a list as advised and where?

like image 830
user3709511 Avatar asked May 06 '20 12:05

user3709511


1 Answers

You need to use an extra bracket around ['Share_Price_Delta_Percent', 'Dividend_Percent']

Like this,

df['Simple_Avg_Return'] = df.groupby(['YF_Ticker'])[['Share_Price_Delta_Percent', 'Dividend_Percent']].transform(
        sum).divide(2).round(2) 

Quoting @ALollz comment

The decision was made https://github.com/pandas-dev/pandas/issues/23566. To keep compatibility between 0.25 and 1.0 they didn't remove the feature but added a warning in 1.0. Likely it will be removed in the next major deprecation cycle.

Source

like image 156
Akash Karnatak Avatar answered Nov 05 '22 00:11

Akash Karnatak