Python FutureWarning:使用多个键进行索引(隐式转换为键元组)

我最近将 Python 升级到 3.7.6 和我现有的代码:


df['Simple_Avg_Return'] = df.groupby(['YF_Ticker'])['Share_Price_Delta_Percent', 'Dividend_Percent'].transform(

        sum).divide(2).round(2) 

现在抛出这个警告:


FutureWarning: Indexing with multiple keys (implicitly converted to a

tuple of keys) will be deprecated, use a list instead.  

我将如何按照建议将其转换为列表以及在哪里?


慕田峪7331174
浏览 506回答 1
1回答

慕桂英3389331

您需要在周围使用一个额外的支架['Share_Price_Delta_Percent', 'Dividend_Percent']像这样,df['Simple_Avg_Return'] = df.groupby(['YF_Ticker'])[['Share_Price_Delta_Percent', 'Dividend_Percent']].transform(         sum).divide(2).round(2)引用@ALollz 评论该决定是在https://github.com/pandas-dev/pandas/issues/23566做出的。为了保持 0.25 和 1.0 之间的兼容性,他们没有删除该功能,而是在 1.0 中添加了警告。它可能会在下一个主要的弃用周期中被删除。资源
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python