将名为station的对象列转换为类别;有些值偏低,而有些则不
列站的值设为a,d,e,F 我尝试了以下代码
data_obs[station] = data_obs[station].astype('category')
data_obs.info()
我希望柱站成为类别,但我遇到一个错误,值MASDEMIAN001(当其他值是巴黎,朗德雷斯时...)
TypeError Traceback (most recent call
last)
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in
pandas._libs.hashtable.Int64HashTable.get_item()
TypeError: an integer is required
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call
last)
<ipython-input-100-ef309af5bdeb> in <module>
1 # Typer les variables catégories de OBSERVATION
----> 2 data_obs[station] = data_obs[station].astype('category')
3 data_obs.info()
~\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()
KeyError: 'MASDEMIAN001'