본문 바로가기

Python

[Python] Warning 경고 메시지 끄기

 

Pandas 에서 형 변환이나 plot 을 그릴 때 FutureWarning 과 같은 Warning 메시지가 다음과 같이 출력창에 도배되는 경우가 있습니다. 

 

 

 

Warning 메시지도 중요한 메시지이지만 매번 발생되는 경우 원하는 출력 결과를 보기 위해서 스크롤을 계속 내려야 합니다. 이 과정이 귀찮기 때문에 다음과 같이 잠시 경고 메시지를 warnings 라이브러리를 사용하여 숨길 수 있습니다. 

 

import warnings 

# 경고 메시지 숨기기
warnings.filterwarnings("ignore")

# 경고 메시지 나타내기 (=기본 설정)
warnings.filterwarnings("default")

 

공식 도큐먼트 : https://docs.python.org/3.9/library/warnings.html#the-warnings-filter

 

warnings — Warning control — Python 3.9.13 documentation

warnings — Warning control Source code: Lib/warnings.py Warning messages are typically issued in situations where it is useful to alert the user of some condition in a program, where that condition (normally) doesn’t warrant raising an exception and te

docs.python.org