Home > OS >  How to display a categorical dataframe in a pairplot
How to display a categorical dataframe in a pairplot

Time:11-12

I am getting the following error: No variables found for grid columns? In the console it prints the dataframe ok, but when I want to display it in seaborn, it doesn't work.

%matplotlib inline
import seaborn as sns
from ipywidgets import interact
import matplotlib.pyplot as plt

cars_url = 'http://archive.ics.uci.edu/ml/machine-learning-databases/car/car.data'
cars_columns = ['buying', 'maint', 'doors', 'persons', 'lug_boot', 'safety', 'class']
data = pd.read_csv(cars_url, names = cars_columns)
data1 = pd.DataFrame(data)
plot(data1)

@interact(hue = ['buying'])
def plot(hue):
    _ = sns.pairplot(data1, hue = hue)

CodePudding user response:

Pairtplot works only with numerical data. You should use Label Encoder before paiplot.

For example:

from sklearn.preprocessing import OrdinalEncoder

encoder = OrdinalEncoder()
data = encoder.fit_transform(data)
  • Related