How to suppress Pandas Future warning ?

I’ve been working some code with python and doing some operation with pandas library.

I used to get future warning in the console like some method is going to changed or deprecated in the future.

So change it to something else like that.

For sometime, it was fine for me. Over period of time, it was bit annoying. Because I was looking for errors description or output in the console. But this future warning message is showing up regularly and reduced my focus towards main items I need to work on.

So I decided to hide those future warning message in the console for a moment. I was looking at the internet and found an generic way to do it.

By adding following line in the code, all the future warning has been hidden from the console.

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

Hope this will be helpful for someone in future or may be for myself.

Happy Coding!

Reference

https://github.com/pandas-dev/pandas/issues/2841#issuecomment-13382440


Related post -> Pandas “Can only compare identically-labeled DataFrame objects” error

Pandas “Can only compare identically-labeled DataFrame objects” error

I’ve been working with pandas to handle a data set and do some operation and analysis.

For a purpose, I have compare two datasets – especially particular fields.

I have faced the following while comparing two fields in my flow.

Can only compare identically-labeled DataFrame objects

For example, I had my code comparison like below

import pandas as pd
dataframe01 = pd.DataFrame(....)
dateframe02 = pd.DataFrame(....)
# Trying to compare and print
print(dataframe01 == dataframe02)

While attempting this approach, I have faced this issue.

From the error message, all I could to understand is labels aren’t matched.

Solution

After referring some docs or online content, I have tried the following approach to compare the data.

print(dataframe01.equals(dataframe02))

This will help us to check whether both the data frames are perfectly matching or not.

There are other options to ignore index labels as well, you can use it based on your needs.

Thanks for reading!


Related post: How to suppress Pandas Future warning ?