<jupyter_start><jupyter_text>Categorical data`Nominal` vs `Ordinal`- Nominal data has no order or ranking between the categories.For example colors: `Yellow`, `Red`, `Green`- Ordinal data has order or ranking between the categories.For example `Cold(1)` < `Warm(2)` < `Hot(3)`<jupyter_code>import numpy as np
import pandas as pd
df = pd.DataFrame(
    data={
        'Breakfast': ['Every day',
                      'Never', 
                      'Rarely',
                      'Most days',
                      'Never',
                      ]
    }
 )
df
from sklearn.preprocessing import LabelEncoder

label_encoder = LabelEncoder()

label_encoder.fit_transform(df['Breakfast'])<jupyter_output><empty_output><jupyter_text>Using the `LabelEncoder` will choose for us the labels.This approach is okay for `nominal` categories, but does not preserve the order or ranking of `ordinal` categories.<jupyter_code>df['Breakfast_encoded'] = label_encoder.fit_transform(df['Breakfast'])

df<jupyter_output><empty_output><jupyter_text>If the categorical data is `ordinal`, then we can custom label it to keep the order of the categories.This could be done using a `dictionary` and `mapping` the categories to the custom labels.<jupyter_code>breakfast_dict = {
    'Never': 1,
    'Rarely': 2,
    'Most days': 3,
    'Every day': 4,
}

df['Breakfast_ordinal'] = df.Breakfast.map(breakfast_dict)
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10759493670886076, 'fraction_numerical': 0.004922644163150493, 'mean_word_length': 3.6809210526315788, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '198232', 'license': 'MIT', 'n_tokens_mistral': 445, 'n_tokens_neox': 431, 'n_words': 130, 'path': 'nominal_vs_ordinal_variables.ipynb', 'repo_name': 'chrismarkella/Kaggle-access-from-Google-Colab', 'size': '1422'}