11

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?

user3709511
  • 221
  • 3
  • 10
  • 3
    Does this answer your question? [Pandas, Future Warning: Indexing with multiple keys](https://stackoverflow.com/questions/60999753/pandas-future-warning-indexing-with-multiple-keys) – cmosig Jul 22 '20 at 09:31

1 Answers1

22

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

Akash Karnatak
  • 678
  • 2
  • 7
  • 16