In this block of code (for full exercise see link below):
# Convert to categorical type nyc_trees['health'] = pd.Categorical( nyc_trees['health'], health_categories, ordered=True ) # Calculate median values median_index = np.median(nyc_trees['health'].cat.codes) median_health_status = health_categories[int(median_index)] print(median_health_status)
In the line where I calculate the median_index, I do not understand how when i call cat .codes, it knows the order of the categories and assigns the right integer to them. Could someone explain that to me?
Thanks in advance