在 Python 代码中使用 pandas 库的 DataFrameGroupBy.sum 函数时,可能会出现 FutureWarning 警告:The default value of numeric_only in DataFrameGroupBy.sum is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.

要解决这个警告,您可以明确指定 numeric_only 参数的值为 True 或者选择只包含数值列的列进行求和操作。以下是修改后的代码:

f7 = f6.groupby(['Area']).sum(numeric_only=True).reset_index()

或者

f7 = f6.groupby(['Area']).select_dtypes(include='number').sum().reset_index()

这样修改后,代码将不再产生警告信息。

Python 代码警告:FutureWarning: DataFrameGroupBy.sum 的 numeric_only 参数

原文地址: https://www.cveoy.top/t/topic/lOn2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录