How to suppress Pandas Future warning ?

前端 未结 3 701
猫巷女王i
猫巷女王i 2020-11-30 19:24

When I run the program, Pandas gives \'Future warning\' like below every time.

D:\\Python\\lib\\site-packages\\pandas\\core\\frame.py:3581: FutureWarning: re         


        
3条回答
  •  暖寄归人
    2020-11-30 20:15

    Warnings are annoying. As mentioned in other answers, you can suppress them using:

    import warnings
    warnings.simplefilter(action='ignore', category=FutureWarning)
    

    But if you want to handle them one by one and you are managing a bigger codebase, it will be difficult to find the line of code which is causing the warning. Since warnings unlike errors don't come with code traceback. In order to trace warnings like errors, you can write this at the top of the code:

    import warnings
    warnings.filterwarnings("error")
    

    But if the codebase is bigger and it is importing bunch of other libraries/packages, then all sort of warnings will start to be raised as errors. In order to raise only certain type of warnings (in your case, its FutureWarning) as error, you can write:

    import warnings
    warnings.simplefilter(action='error', category=FutureWarning)
    

提交回复
热议问题