【问题标题】:How to resolve AttributeError: 'Series' object has no attribute '_mgr'如何解决 AttributeError:“系列”对象没有属性“_mgr”
【发布时间】:2020-12-26 05:08:31
【问题描述】:

我正在尝试在 pandas 的列上使用简单的 .apply 函数,这会产生此错误。很快就需要这方面的帮助。这是我的第一个问题,请忽略我的编辑和结构问题。

data = {'A':[1, 2, 3],  
            'B':[4, 5, 6],  
            'C':[7, 8, 9] } 
df = pd.DataFrame(data) 
df['add'] = df.apply(lambda row : row['A'] + row['B'] + row['C'], axis = 1)

我在 Pandas 中的任何简单的 .apply() 函数中都收到此错误。列上的任何 apply() 都会导致此问题。

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<command-2941072546244745> in <module>
      3             'C':[7, 8, 9] } 
      4 df = pd.DataFrame(data)
----> 5 df['add'] = df.apply(lambda row : row['A'] + row['B'] + row['C'], axis = 1)

/databricks/python/lib/python3.7/site-packages/pandas/core/frame.py in apply(self, func, axis, raw, result_type, args, **kwds)
   6876              format.
   6877         DataFrame.pivot_table : Create a spreadsheet-style pivot table
-> 6878              as a DataFrame.
   6879 
   6880         Notes

/databricks/python/lib/python3.7/site-packages/pandas/core/apply.py in get_result(self)
    183             return self.apply_raw()
    184 
--> 185         return self.apply_standard()
    186 
    187     def apply_empty_result(self):

/databricks/python/lib/python3.7/site-packages/pandas/core/apply.py in apply_standard(self)
    274 
    275     def apply_standard(self):
--> 276         results, res_index = self.apply_series_generator()
    277 
    278         # wrap results

/databricks/python/lib/python3.7/site-packages/pandas/core/apply.py in apply_series_generator(self)
    301         else:
    302             with option_context("mode.chained_assignment", None):
--> 303                 for i, v in enumerate(series_gen):
    304                     # ignore SettingWithCopy here in case the user mutates
    305                     results[i] = self.f(v)

/databricks/python/lib/python3.7/site-packages/pandas/core/apply.py in series_generator(self)
    410         #  of it.  Kids: don't do this at home.
    411         ser = self.obj._ixs(0, axis=0)
--> 412         mgr = ser._mgr
    413         blk = mgr.blocks[0]
    414 

/databricks/python/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5272         """
   5273         Return a Numpy representation of the DataFrame.
-> 5274 
   5275         .. warning::
   5276 

AttributeError: 'Series' object has no attribute '_mgr'

【问题讨论】:

标签: python pandas series


【解决方案1】:

当我尝试在 azure-databricks 集群上运行它时,由于集群管理问题而出现此问题。

清除状态并再次运行即可解决。

_mgr 通常是集群/编译器管理器问题。

【讨论】:

    猜你喜欢
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-23
    • 2020-11-11
    • 2019-04-22
    • 2019-07-26
    相关资源
    最近更新 更多