np.ptp 的弃用警告

Deprecation warning for np.ptp

我正在使用 Python 并且在使用以下代码时

df['timestamp'] = df.groupby(["id"]).timestamp.transform(np.ptp)

我收到警告 FutureWarning: Method .ptp is deprecated and will be removed in a future version. Use numpy.ptp instead.df 是一个 Pandas DataFrame,timestamp 和 id 是 columns。我认为 np.ptp 导致了这个警告。

我需要更改什么?

这意味着 方法 .ptp 正在被弃用,取而代之的是(据我所读)function np.ptp() 所以你可以将警告设置为 false 以便不读取它,或者用 numpy 看起来的函数替换方法提出建议。

如果你想抑制警告,你可以尝试: warnings.filterwarnings('ignore') 或 warnings.simplefilter('ignore', FutureWarning) 如果您忽略的只是 FutureWarning。