I’m trying to plot a pairplot
of my dataset using Seaborn, but I’m encountering an error related to infinite values. Here is the code I’m using:
import seaborn as sns
import matplotlib.pyplot as plt
sns.pairplot(df_train[cols], height=2.5)
plt.show()
However, I get the following warning:
C:Usersjpinoanaconda3Libsite-packagesseaborn_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.
with pd.option_context('mode.use_inf_as_na', True):
How can I handle the infinite values in my dataset to avoid this warning and successfully plot the pairplot?
José Antonio Pino Morales is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
use a lambda
function with apply
to replace the infinite values.
sns.pairplot(df_train[cols].apply(lambda x: x.replace([np.inf, -np.inf], np.nan)).dropna(), height=2.5)
plt.show()
Vinod Baste is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.