I'm extracting values from a pandas series. The column data type is object. Everything up to creating the series if OK, but extracting a value from the series generates a KeyError. What am I missing?
Created a dataframe from a csv file and generated a series
migrants.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 6459 entries, 1 to 716
Data columns (total 6 columns):
```
area 6459 non-null object
```
dtypes: int64(1), object(5)
memory usage: 513.2+ KB
migrants_area = migrants["area"]
type(migrants_area)
pandas.core.series.Series
migrants_europe = migrants_area["Europe"]
KeyError Traceback (most recent call last)
<ipython-input-44-5cd582f027de> in <module>
----> 1 migrants_europe = migrants_area["Europe"]
~\Anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
765 key = com._apply_if_callable(key, self)
766 try:
--> 767 result = self.index.get_value(self, key)
768
769 if not is_scalar(result):
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
3116 try:
3117 return self._engine.get_value(s, k,
-> 3118 tz=getattr(series.dtype, 'tz', None))
3119 except KeyError as e1:
3120 if len(self) > 0 and self.inferred_type in ['integer', 'boolean']:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine._get_loc_duplicates()
pandas\_libs\index_class_helper.pxi in pandas._libs.index.Int64Engine._maybe_get_bool_indexer()
KeyError: 'Europe
I expect the output to be all occurrences of "Europe" from the series