TypeError:UFUNC的循环不支持没有可呼叫的EXP方法的类型Float的参数0
这是我的数据集,
Id B C
1 0.784 -1.6745
2 2.123 -2.8934
这是我尝试
import numpy as np
df.apply(lambda x: np.exp(x)/(1+np.exp(x)))
错误消息的内容
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
AttributeError: 'float' object has no attribute 'exp'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<ipython-input-43-288751cc2e1d> in <module>
----> 1 A.apply(lambda x: np.exp(x)/(1+np.exp(x)))
~/.local/lib/python3.6/site-packages/pandas/core/frame.py in apply(self, func, axis, raw, result_type, args, **kwds)
7550 kwds=kwds,
7551 )
-> 7552 return op.get_result()
7553
7554 def applymap(self, func) -> "DataFrame":
~/.local/lib/python3.6/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):
~/.local/lib/python3.6/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
~/.local/lib/python3.6/site-packages/pandas/core/apply.py in apply_series_generator(self)
303 for i, v in enumerate(series_gen):
304 # ignore SettingWithCopy here in case the user mutates
--> 305 results[i] = self.f(v)
306 if isinstance(results[i], ABCSeries):
307 # If we have a view on v, we need to make a copy because
<ipython-input-43-288751cc2e1d> in <lambda>(x)
----> 1 A.apply(lambda x: np.exp(x)/(1+np.exp(x)))
~/.local/lib/python3.6/site-packages/pandas/core/series.py in __array_ufunc__(self, ufunc, method, *inputs, **kwargs)
724
725 inputs = tuple(extract_array(x, extract_numpy=True) for x in inputs)
--> 726 result = getattr(ufunc, method)(*inputs, **kwargs)
727
728 name = names[0] if len(set(names)) == 1 else None
TypeError: loop of ufunc does not support argument 0 of type float which has no callable exp method
Here's my dataset
Id B C
1 0.784 -1.6745
2 2.123 -2.8934
Here's what I try
import numpy as np
df.apply(lambda x: np.exp(x)/(1+np.exp(x)))
The error message
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
AttributeError: 'float' object has no attribute 'exp'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<ipython-input-43-288751cc2e1d> in <module>
----> 1 A.apply(lambda x: np.exp(x)/(1+np.exp(x)))
~/.local/lib/python3.6/site-packages/pandas/core/frame.py in apply(self, func, axis, raw, result_type, args, **kwds)
7550 kwds=kwds,
7551 )
-> 7552 return op.get_result()
7553
7554 def applymap(self, func) -> "DataFrame":
~/.local/lib/python3.6/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):
~/.local/lib/python3.6/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
~/.local/lib/python3.6/site-packages/pandas/core/apply.py in apply_series_generator(self)
303 for i, v in enumerate(series_gen):
304 # ignore SettingWithCopy here in case the user mutates
--> 305 results[i] = self.f(v)
306 if isinstance(results[i], ABCSeries):
307 # If we have a view on v, we need to make a copy because
<ipython-input-43-288751cc2e1d> in <lambda>(x)
----> 1 A.apply(lambda x: np.exp(x)/(1+np.exp(x)))
~/.local/lib/python3.6/site-packages/pandas/core/series.py in __array_ufunc__(self, ufunc, method, *inputs, **kwargs)
724
725 inputs = tuple(extract_array(x, extract_numpy=True) for x in inputs)
--> 726 result = getattr(ufunc, method)(*inputs, **kwargs)
727
728 name = names[0] if len(set(names)) == 1 else None
TypeError: loop of ufunc does not support argument 0 of type float which has no callable exp method
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来像数据类型问题。
信息:
应用:
结果:
复制错误:
Looks like a data type issue.
Info:
Apply:
Result:
Reproduce error: