在 Pandas Dataframe 上调用 seaborn 的 pairplot 时不会出现图 [英] Plots do not appear when calling seaborn's pairplot on a pandas Dataframe
问题描述
我有一个看起来像这样的数据框
I have a Dataframe that looks like so
Price Mileage Age
4250 71000 8
6500 43100 6
26950 10000 3
1295 78000 17
5999 61600 8
这被分配给dataset
.我只是简单地调用 sns.pairplot(dataset)
并且只剩下一个图表——价格在我的数据集中的分布.我希望有一个 3x3 的绘图网格.
This is assigned to dataset
. I simply call sns.pairplot(dataset)
and I'm left with just a single graph - the distribution of prices across my dataset. I expected a 3x3 grid of plots.
当我从 seaborn 导入预先配置的数据集时,我得到了预期的多图对图.
When I import a pre-configured dataset from seaborn I get the expected multiplot pair plot.
我是 seaborn 的新手,如果这是一个愚蠢的问题,我深表歉意,但我做错了什么?这似乎是一项简单的任务.
I'm new to seaborn so apologies if this is a silly question, but what am I doing wrong? It seems like a simple task.
推荐答案
从您的评论来看,您似乎正在尝试在非数字列上绘图.先尝试强制他们:
From your comment, it seems like you're trying to plot on non-numeric columns. Try coercing them first:
dataset = dataset.apply(lambda x: pd.to_numeric(x, errors='coerce'))
sns.pairplot(dataset)
errors='coerce'
参数会将不可强制的值(您的列首先是对象的原因)替换为 NaN.
The errors='coerce'
argument will replace non-coercible values (the reason your columns are objects in the first place) to NaN.
这篇关于在 Pandas Dataframe 上调用 seaborn 的 pairplot 时不会出现图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!