D:\14595\anaconda3\lib\site-packages\pandas\core\generic.py:6392: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame这个也是
时间: 2023-07-06 17:34:36 浏览: 101
pandas DataFrame 警告(SettingWithCopyWarning)的解决
这个warning是由于使用了Pandas的切片操作,并且对切片后的数据进行了修改。为了避免这个warning,可以使用Pandas提供的`.loc`方法来进行切片和修改操作。例如,将:
```
df = pd.DataFrame(...)
df_filtered = df[df['column'] > 0]
df_filtered['new_column'] = 1
```
改为:
```
df = pd.DataFrame(...)
df_filtered = df.loc[df['column'] > 0]
df_filtered.loc[:, 'new_column'] = 1
```
这样就可以避免这个warning了。另外,也可以使用以下代码来忽略这个warning:
```
import warnings
warnings.filterwarnings("ignore", message="A value is trying to be set on a copy of a slice from a DataFrame")
```
阅读全文