# Exploring categorical data

Such variables take a fixed and limited number of possible values. For example, classes, gender, blood type, etc. Also, in the case of categorical variables, the logical order does not match the categorical data, for example, "one", "two", "three". But the sorting of these variables uses a logical order. For example, gender is a categorical variable and has categories — male and female, and there is no internal order in the categories. A purely categorical variable — it is a variable that allows you to simply assign categories, but you cannot clearly order the variables.

Terms related to volatility metrics:

• Mode: most frequent value in data
Example-
` Data = ["Car", "Bat", "Bat", "Car", " Bat "," Bat "," Bat "," Bike "] Mode =" Bat "`
• Expected value: When working in machine learning, the categories must be linked with a numerical value to give an understanding of the machine. This gives an average based on the likelihood of the category appearing, i.e. expected value.
Calculated by —
` -" Multiply each outcome by its probability of occurring. -" Sum these values ​​`

Thus, the sum of the values ​​multiplied by the probability of their occurrence is often used to sum the levels of variable factors.

• • Histograms: the frequency of each category, presented as columns.

` `

` import matplotlib.pyplot as plt import numpy as np `

` `

Data —

Indexing data —

 ` label ` ` = ` ` [` ` ’Car’ ` `, ` `’ B ike’ ` `, ` ` ’Truck’ ` `, ` ` ’Cycle’ ` `, ` `’ Jeeps’ ` `, ` ` ’Amulance’ ` `] ` ` no_vehicle ` ` = ` ` [` ` 941 ` `, ` ` 854 ` `, ` ` 4595 ` ` , ` ` 2125 ` `, ` ` 942 ` `, ` ` 509 ` `] `
 ` index ` ` = ` ` np.arange (` ` len ` ` (label)) `   ` print ` ` (` ` "Total Labels:" ` `, ` ` len ` ` (label)) ` ` print ` ` (` `" Indexing: "` `, index) `

Exit :

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

Histogram —

 ` 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 () `

Exit:

•  Pie charts: The frequency of each category, represented as pie charts. It is a pie chart where the arc length of each slice is proportional to the amount it represents.

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

Output:

## Shop Learn programming in R: courses

\$FREE Best Python online courses for 2022

\$FREE Best laptop for Fortnite

\$399+ Best laptop for Excel

\$ Best laptop for Solidworks

\$399+ Best laptop for Roblox

\$399+ Best computer for crypto mining

\$499+ Best laptop for Sims 4

\$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries