What is the best way to replace NaN values for ranked columns

I have a column named BsmntQual that gives a ranking on the height of the basement per each house. These are all of the unique values in this column:

print(train['BsmtQual'].unique().tolist())

>>> ['Gd', 'TA', 'Ex', nan, 'Fa']


This is the legend of this particular column:

BsmtQual: Evaluates the height of the basement

Ex   Excellent (100+ inches)
Gd   Good (90-99 inches)
TA   Typical (80-89 inches)
Fa   Fair (70-79 inches)
Po   Poor (<70 inches
NA   No Basement < Not to be confused with the nan value above


This is what I did for my other ranked columns but this one did not have NaN values:

train['ExterQual'] = train['ExterQual'].replace(['Ex', 'Gd', 'TA', 'Fa'], [4, 3, 2, 1])  # Exterior Quality


For numerical values, a common way is to fill all NaN values with the mean of the column. But what is a good way of replacing the NaN values for columns such as these?

Here is the full dataset

Your legend clearly states that missing values mean that there is no basement. You could fill the missing values with ’NoBase’ to make that point clearer (train[‘BsmtQual’].fillna(‘NoBase’, inplace=True)). When you rank them then, you just add another ranking for ‘NoBase’, maybe 0, based on your example rating that gives a higher value to more quality.
• @yoav_aaa Good catch. Andros, if you want to ignore that behavior, you can set keep_default_na = False to keep pandas from reading NA as nan, and it will just leave those values as the string 'NA'. – HS-nebula Jul 1 at 13:36