-1

I am trying to use a simple .apply function on a column in pandas, this is creating this error. Need help on this pretty soon. This is my first question, please ignore my edits and structure issues.

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)

I am getting this error in any simple .apply() function in Pandas. Any apply() on columns is leading to this issue.

---------------------------------------------------------------------------
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'
srishtigarg
  • 1,106
  • 10
  • 24

1 Answers1

3

This issue was occurring due to cluster management issue while I was trying to run it on a azure-databricks cluster.

Clearing the state and running again resolved it.

_mgr is generally a cluster/compiler manager issue.

srishtigarg
  • 1,106
  • 10
  • 24