我正在从熊猫系列中提取值。列数据类型是对象。一切顺利,直到创建序列为止,但是从序列中提取值都会生成KeyError。我想念什么?
从csv文件创建数据框并生成一系列
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
我希望输出的是该系列中所有出现的“欧洲”