Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Pandas – How to supress PerformanceWarning?

How I can supress a PerformanceWarning in pandas?

I've already tried warnings.simplefilter(action='ignore', category=PerformanceWarning), but it gives me a NameError: name 'PerformanceWarning' is not defined

like image 965
Vaiaro Avatar asked Jul 25 '18 14:07

Vaiaro


People also ask

How do you stop SettingWithCopyWarning in pandas?

Generally, to avoid a SettingWithCopyWarning in Pandas, you should do the following: Avoid chained assignments that combine two or more indexing operations like df["z"][mask] = 0 and df. loc[mask]["z"] = 0 . Apply single assignments with just one indexing operation like df.

How do I ignore performance warning in Python?

To suppress any warnings in the script, import the warnings library, and pass the filterwarnings() function the argument ignore .


1 Answers

PerformanceWarning is not a built-in warning class so you can't call it directly in category argument. You can try the following code:

import pandas as pd
import warnings

warnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)

I have no idea how to reproduce the PerformanceWarning but i tested a similar approach to the "SettingWithCopyWarning" pandas warning and it worked. Let me know if it works.

like image 127
FiloCara Avatar answered Nov 06 '22 04:11

FiloCara