# Categorical Data

Categorical data represents variables that fall into distinct categories or groups rather than numerical values. These categories are often labels or names, such as "gender," "region," or "product type," and they can be nominal (without a meaningful order) or ordinal (with an inherent order). For example, "colors" is nominal (e.g., teal, red, green), while "education level" (e.g., high school, bachelor's, master's) is ordinal. Categorical data is commonly used in surveys, demographics, and classification problems.&#x20;

Analyzing and visualizing categorical data is essential for understanding distributions, identifying dominant groups, and exploring relationships between categories. Tools like bar charts, pie charts, and frequency tables are commonly used to summarize and represent this data effectively.&#x20;

In Python,  most categorical data is saved as `string` in pandas, but pandas also has a special data type called `category` to optimize memory usage and performance.  Understanding and processing categorical data correctly is vital for drawing meaningful insights and performing accurate analyse

***

### Code Example

How it appears in Pandas:

```
data = {
    'Category': ['A', 'B', 'A', 'C']
}

df = pd.DataFrame(data)
df['Category'] = df['Category'].astype('category')
print(df)
```

Output:

```
  Category
0       A
1       B
2       A
3       C
```
