Pandas报错TypeError:NDFrame.describe()不支持datetime_is_numeric参数
错误原因与解决方法
错误原因
升级Pandas后出现该错误,是因为datetime_is_numeric这个参数在新版本Pandas(2.0及以上)中已被移除。旧版本Pandas里,该参数用于开启datetime类型数据的数值化统计计算;而新版本Pandas默认就会对datetime类型执行这类统计,不再需要该参数。
解决方法
- 直接修改代码:删除
describe()方法中的datetime_is_numeric=True参数即可,修改后代码如下:check_in_duration = df["Check-In Time"].describe() - 兼容新旧版本(可选):如果需要代码同时适配新旧Pandas版本,可以添加版本判断逻辑:
import pandas as pd if pd.__version__ >= "2.0.0": check_in_duration = df["Check-In Time"].describe() else: check_in_duration = df["Check-In Time"].describe(datetime_is_numeric=True)
内容的提问来源于stack exchange,提问作者KleberQueiroz
相关产品推荐
相关产品推荐

