How to ignore ‘settingswithcopy’ warning in Python
To ignore the SettingWithCopyWarning
warning in Python, you can use the pd.options.mode.chained_assignment
setting. This setting controls whether or not the SettingWithCopyWarning
warning will be raised when you make a copy of a slice of a DataFrame. To suppress this warning, you can set this option to None
like this:
import pandas as pd
pd.options.mode.chained_assignment = None
This will suppress the warning for the entire program. Alternatively, you can use the warnings
module to filter out this specific warning like this:
import warnings
warnings.filterwarnings("ignore", category=SettingWithCopyWarning)
This will also suppress the warning, but only for the code that comes after the warnings.filterwarnings
call.