指定fillna的限制尚未实施

我想用method ='bfill'和一个限制在熊猫数据帧上实现fillna方法

labeled_features = final_feat.merge(failures,on=['datetime','machineID'],how='left')
print(type(labeled_features))
labeled_features = labeled_features.bfill(limit=7) # fill backward up to 24h
labeled_features = labeled_features.fillna('none')
labeled_features.head()

但是我遇到以下错误

<class 'pandas.core.frame.DataFrame'>

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-40-f9d11ab337a0> in <module>
      1 labeled_features = final_feat.merge(failures,how='left')
      2 print(type(labeled_features))
----> 3 labeled_features = labeled_features.bfill(limit=7) # fill backward up to 24h
      4 labeled_features = labeled_features.fillna('none')
      5 labeled_features.head()

c:\users\risha\appdata\local\programs\python\python37\lib\site-packages\pandas\core\generic.py in bfill(self,axis,inplace,limit,downcast)
   6312         """
   6313         return self.fillna(
-> 6314             method="bfill",axis=axis,inplace=inplace,limit=limit,downcast=downcast
   6315         )
   6316 

c:\users\risha\appdata\local\programs\python\python37\lib\site-packages\pandas\core\frame.py in fillna(self,value,method,downcast,**kwargs)
   4257             limit=limit,4258             downcast=downcast,-> 4259             **kwargs
   4260         )
   4261 

c:\users\risha\appdata\local\programs\python\python37\lib\site-packages\pandas\core\generic.py in fillna(self,downcast)
   6235                 inplace=inplace,6236                 coerce=True,-> 6237                 downcast=downcast,6238             )
   6239         else:

c:\users\risha\appdata\local\programs\python\python37\lib\site-packages\pandas\core\internals\managers.py in interpolate(self,**kwargs)
    567 
    568     def interpolate(self,**kwargs):
--> 569         return self.apply("interpolate",**kwargs)
    570 
    571     def shift(self,**kwargs):

c:\users\risha\appdata\local\programs\python\python37\lib\site-packages\pandas\core\internals\managers.py in apply(self,f,axes,filter,do_integrity_check,consolidate,**kwargs)
    436                     kwargs[k] = obj.reindex(b_items,copy=align_copy)
    437 
--> 438             applied = getattr(b,f)(**kwargs)
    439             result_blocks = _extend_blocks(applied,result_blocks)
    440 

c:\users\risha\appdata\local\programs\python\python37\lib\site-packages\pandas\core\internals\blocks.py in interpolate(self,fill_value,**kwargs)
   1963         values = self.values if inplace else self.values.copy()
   1964         return self.make_block_same_class(
-> 1965             values=values.fillna(value=fill_value,method=method,limit=limit),1966             placement=self.mgr_locs,1967         )

c:\users\risha\appdata\local\programs\python\python37\lib\site-packages\pandas\util\_decorators.py in wrapper(*args,**kwargs)
    206                 else:
    207                     kwargs[new_arg_name] = new_arg_value
--> 208             return func(*args,**kwargs)
    209 
    210         return wrapper

c:\users\risha\appdata\local\programs\python\python37\lib\site-packages\pandas\core\arrays\categorical.py in fillna(self,limit)
   1842         if limit is not None:
   1843             raise NotImplementedError(
-> 1844                 "specifying a limit for fillna has not " "been implemented yet"
   1845             )
   1846 

NotImplementedError: specifying a limit for fillna has not been implemented yet

在此讨论中,我发现存在一个错误,但此后我没有找到其他答案。 https://github.com/pandas-dev/pandas/issues/1892

我使用了关键字方法,但仍然无法正常工作pandas.Series / DataFrame.fillna限制中的错误?

如果我取消限制,它将正常工作,但是下一行将引发错误

labeled_features = labeled_features.fillna('none')

ValueError:填充值必须在类别中

gdp2009 回答:指定fillna的限制尚未实施

请与bfillaxis=1一起使用limit=7

labeled_features = labeled_features.bfill(axis=1,limit=7)
,

面临同样的问题。 显然,这是由于“失败”列属于“数据类型分类”这一事实。 使用以下命令更改数据类型:

labeled_features.failure = labeled_features.failure.astype(str)

然后执行以下代码:

labeled_features.failure = labeled_features.failure.fillna(method='bfill',limit=7)

本文链接:https://www.f2er.com/2829503.html

大家都在问