How to hide warnings in Python
Welcome back! As most of you may know, Python can throw a warning at you at any given time, although these warnings can be sometimes useful, most of us probably just want to avoid seeing those red warning blocks come up. Luckily for us, there is an awesome Python package that allows us to avoid these types of warnings! The warnings package is exactly what we’re looking for, if you want the complete documentation of this package, check out the link below:
Let’s go ahead and get this package working in our environment, luckily for us this specific package should be built inside of Python for us, all we have to do is import the warnings package:
import warnings
At this point we need to setup our filter, to do this we need to essentially ignore the warnings that pop up, to do this we use the following command:
warnings.filterwarnings(action=’ignore’)
As long as those commands are at the top of your Python script, all of the warnings that may come up will essentially be hidden! Let’s go ahead and see it in action, the warnings…