KeyError while accessing columns in movies_income_cleaned dataframe

i don’t understand the error that is coming when coding for dropdown on country coulmn. KeyError is written in error when i try to access the country column from movies_income_cleaned dataframe even though country column is there in movies_income_cleaned dataframe.

keyerror means that there is no country column in movie_income_cleaned dataframe.
print the movie_income_cleaned dataframe and see the output. (if you have exploded country column before it then might be its column name is country_list or something else. just check it properly)
Also you code line
does not make sense (though this is not the cause of error) because if you drop country column from list_country then nothing is left in list_country dataframe.

after this cell you have done dropna can you also show how does movies_income_cleaned looks like after that.
It would be even better if you give the colab link in here where you are working with code (share it with the setting anyone with the link can edit)

I checked your colab and ran the same code again on my side the error is not coming now. Most probably there is some bug with your colab. I would suggest to restart the colab and run the code again.

Another issue with you code which is unrelated to above error is this line


this line does not remove any row where country is null. You can check this simply by


if you want to drop rows where only country column is null you need to use below code


or in this question you can also do fillna . You can fillna all the nulls of country with ‘NO COUNTRY’ word.