【问题标题】:Python FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) [duplicate]Python FutureWarning:使用多个键进行索引(隐式转换为键元组)[重复]
【发布时间】:2020-05-06 12:03:45
【问题描述】:

我最近将 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.  

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

【问题讨论】:

标签: python group-by


【解决方案1】:

您需要在['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 中添加了警告。可能会在下一个被删除 主要的弃用周期。

Source

【讨论】:

    猜你喜欢
    • 2019-03-19
    • 2021-05-29
    • 1970-01-01
    • 2019-03-06
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 2019-04-14
    • 2021-07-13
    相关资源
    最近更新 更多