Open In App

Exploring Categorical Data

Categorical Variable/Data (or Nominal variable): Such variables take on a fixed and limited number of possible values. For example – grades, gender, blood group type, etc. Also, in the case of categorical variables, the logical order is not the same as categorical data e.g. “one”, “two”, “three”. But the sorting of these variables uses logical order. For example, gender is a categorical variable and has categories – male and female and there is no intrinsic ordering to the categories. A purely categorical variable is one that simply allows you to assign categories, but you cannot clearly order the variables. Terms related to Variability Metrics : 

Data = ["Car", "Bat", "Bat", "Car", "Bat", "Bat", "Bat", "Bike"]
Mode = "Bat"
-> Multiply each outcome by its probability of occurring.
-> Sum these values




import matplotlib.pyplot as plt
import numpy as np




label = ['Car', 'Bike', 'Truck', 'Cycle', 'Jeeps', 'Ambulance']
no_vehicle = [941, 854, 4595, 2125, 942, 509]




index = np.arange(len(label))
 
print ("Total Labels : ", len(label))
print ("Indexing : ", index)

Total Labels :  6
Indexing :  [0 1 2 3 4 5]




plt.bar(index, no_vehicle)
plt.xlabel('Type', fontsize = 15)
plt.ylabel('No of Vehicles', fontsize = 15)
plt.xticks(index, label, fontsize = 10, rotation = 30)
plt.title('Market Share for Each Genre 1995-2017')
 
plt.show()




plt.figure(figsize =(8, 8))
plt.pie(no_vehicle, labels = label,
        startangle = 90, autopct ='%.1f %%')
plt.show()


Article Tags :