我试图在下面把两个字段分开:

c1_preds_data['adj_final_price'] = (c1_preds_data["final_price "]/c1_preds_data['adjustment'])

在Pandas数据帧中,AM收到以下错误消息:
TypeError: ufunc 'true_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

我试过df.dropna(),因为我是用N/a除以的,我试过检查分母中没有任何零,如下所示:
c1_preds_data.loc[c1_preds_data.adjustment == 0, 'adj_final_flag'] = -99
c1_preds_data.loc[c1_preds_data.adjustment != 0, 'adj_final_flag'] = 99

它们都是非零的(99)
不确定如何解释错误消息。

最佳答案

您正在尝试对字符串执行仅可用于数值类型的操作。(可能是从试图保留价格数据的pip或point精度的sql数据库中获得的?)
如果要保持pip/点精度,应该考虑将乘数作为int存储在不同的表中,并将其与汇率对关联起来。
首先,将序列重铸为浮动,然后执行操作。
c1_preds_data["final_price "] = c1_preds_data["final_price "].astype('float')
c1_preds_data['adjustment'] = c1_preds_data['adjustment'].astype('float')
看起来你在做一个平行测试。祝你好运!

08-16 19:46