我有以下一句话:
b['trucks_est'] = math.ceil(b['volume'] / b['max_boxes_per_truck'])
这将引发此例外情况:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
C:\Users\HUGO~1.VIL\AppData\Local\Temp/ipykernel_12504/708959517.py in <module>
----> 1 b['trucks_est'] = math.ceil(
2 b['volume'] / b['max_boxes_per_truck'])
~\Documents\code\Venv\lib\site-packages\pandas\core\series.py in wrapper(self)
183 if len(self) == 1:
184 return converter(self.iloc[0])
--> 185 raise TypeError(f"cannot convert the series to {converter}")
186
187 wrapper.__name__ = f"__{converter.__name__}__"
TypeError: cannot convert the series to <class 'float'>
我知道问题在于math.ceiling()
,因为b['trucks_est'] = b['volume'] / b['max_boxes_per_truck']
工作得很完美。
我怎样才能对熊猫数据进行数学运算呢?
发布于 2022-01-21 00:10:14
看起来你想要这样做:
b['trucks_est'] = np.ceil(b['volume'] / b['max_boxes_per_truck'])
指向文档的链接:https://numpy.org/doc/stable/reference/generated/numpy.ceil.html
https://stackoverflow.com/questions/70794225
复制相似问题