Issue
I want to know all the information from columns 13 to 21 and compare it to column 1 (and specify the value as '1'). I checked previous similar errors and I did not see any spaces yet I'm still encountering this error, does anyone know why?
Here is my code:
hotel_bookings.loc[hotel_bookings.is_canceled==1,hotel_bookings.country]
Here is the error:
KeyError Traceback (most recent call last)
<ipython-input-148-91ca78d709e4> in <module>()
----> 1 hotel_bookings.loc[hotel_bookings.is_canceled==1,hotel_bookings.country]
6 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/indexing.py in _validate_read_indexer(self, key, indexer, axis)
1372 if use_interval_msg:
1373 key = list(key)
-> 1374 raise KeyError(f"None of [{key}] are in the [{axis_name}]")
1375
1376 not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())
KeyError: "None of [Index(['PRT', 'PRT', 'GBR', 'GBR', 'GBR', 'GBR', 'PRT', 'PRT', 'PRT', 'PRT',\n ...\n 'DEU', 'DEU', 'JPN', 'DEU', 'BEL', 'BEL', 'FRA', 'DEU', 'GBR', 'DEU'],\n dtype='object', length=119390)] are in the [columns]"
Solution
Instead Series hotel_bookings.country
use only column name country
:
hotel_bookings.loc[hotel_bookings.is_canceled==1, 'country']
Answered By - jezrael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.