import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df= pd.read_csv(r'C:\Users\Vikipedia\Downloads\mushrooms.csv')
df.head()
Calculate the unique number of each category of each column:
X = df.drop('class', axis=1)
y = df['class']
y = y.map({'p':'Posionous','e': 'Edible'})
cat_cols= X.select_dtypes(include='object').columns.tolist()
for col in cat_cols:
print (f" col name : {col}, N Unique : {X[col].nunique()}")
Compute and generate a table:
for col in cat_cols:
X[col]=X[col].asty