Plots do not appear when calling seaborn's pairplot on a pandas Dataframe

会有一股神秘感。 提交于 2019-12-25 02:28:06

问题


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 

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.

When I import a pre-configured dataset from seaborn I get the expected multiplot pair plot.

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.


回答1:


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)

The errors='coerce' argument will replace non-coercible values (the reason your columns are objects in the first place) to NaN.



来源:https://stackoverflow.com/questions/54132449/plots-do-not-appear-when-calling-seaborns-pairplot-on-a-pandas-dataframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!