问题描述
我试图在 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,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'
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)