这个警告是由于对一个切片副本进行修改时引起的。为了解决这个问题,可以使用.loc.copy()方法来明确地指定对原始数据的修改。

以下是两种解决方法:

  1. 使用.loc方法:
df_data.loc[:, "tag"].fillna('', inplace=True)
  1. 使用.copy()方法创建数据副本:
df_data_copy = df_data.copy()
df_data_copy["tag"].fillna('', inplace=True)

这两种方法都会明确指定对原始数据的修改,从而避免SettingWithCopyWarning警告。

df_datatagfillnainplace=True 报SettingWithCopyWarning A value is trying to be set on a copy of a slice from a DataFrame问题怎么解决

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

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