Error in code at line 72

Hello,

As suggested in the class changed line 72 of original to -
train_inputs[encoded_cols] = encoder.transform(train_inputs[categorical_cols].fillna(‘Unknown’))
val_inputs[encoded_cols] = encoder.transform(val_inputs[categorical_cols].fillna(‘Unknown’))
test_inputs[encoded_cols] = encoder.transform(test_inputs[categorical_cols].fillna(‘Unknown’))

However still have run into an error -

None of [{key}] are in the [{axis_name}
We (temporarily) allow for some missing keys with .loc, except in
KeyError: “None of [Index([‘Location_Adelaide’, ‘Location_Albany’, ‘Location_Albury’,\n ‘Location_AliceSprings’, ‘Location_BadgerysCreek’, ‘Location_Ballarat’,\n ‘Location_Bendigo’, ‘Location_Brisbane’, ‘Location_Cairns’,\n ‘Location_Canberra’,\n …\n ‘WindDir3pm_SE’, ‘WindDir3pm_SSE’, ‘WindDir3pm_SSW’, ‘WindDir3pm_SW’,\n ‘WindDir3pm_Unknown’, ‘WindDir3pm_W’, ‘WindDir3pm_WNW’,\n ‘WindDir3pm_WSW’, ‘RainToday_No’, ‘RainToday_Yes’],\n dtype=‘object’, length=102)] are in the [columns]”

Please help.

1 Like

Hey, the problem is not in this cell, this cell looks fine to me, you are somehow updating the values of some rows in the inputs dataframes or your encoder is wrong. Try printing the input dataframes and check whats changed in them.

Hey I checked the input dataframes.
this part " encoder.transform(train_inputs[categorical_cols].fillna(‘unknown’)) "
is not showing any error , but train_inputs[encoded_cols] this shows " “None of [Index([‘Location_Adelaide’, ‘Location_Albany’, ‘Location_Albury’,\n ‘Location_AliceSprings’, ‘Location_BadgerysCreek’, ‘Location_Ballarat’,\n ‘Location_Bendigo’, ‘Location_Brisbane’, ‘Location_Cairns’,\n ‘Location_Canberra’,\n …\n ‘WindDir3pm_SE’, ‘WindDir3pm_SSE’, ‘WindDir3pm_SSW’, ‘WindDir3pm_SW’,\n ‘WindDir3pm_W’, ‘WindDir3pm_WNW’, ‘WindDir3pm_WSW’,\n ‘WindDir3pm_unknown’, ‘RainToday_No’, ‘RainToday_Yes’],\n dtype=‘object’, length=102)] are in the [columns]”

What should I do next?

Hello @ananyakv-ghosh, I don’t think it will give an error if you do,
train_inputs[encoded_cols] = encoder.transform(train_inputs[categorical_cols].fillna(‘unknown’))
If you just execute train_inputs[encoded_cols] it will give an error cause encoded_cols are not in the inputs dataframe initially.

It’s still showing the same error