Chr*_*Ell 5 python python-3.x pandas
我试图在下面将两个字段相互划分:
c1_preds_data['adj_final_price'] = (c1_preds_data["final_price "]/c1_preds_data['adjustment'])
Run Code Online (Sandbox Code Playgroud)
在 Pandas DataFrame 中,我收到以下错误消息:
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''
Run Code Online (Sandbox Code Playgroud)
我试过 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
Run Code Online (Sandbox Code Playgroud)
他们都以非零的形式出现 (99)
并且不确定如何解释错误消息。
您正在尝试对仅适用于数字类型的字符串执行操作。(也许来自试图保留价格数据的点数或点精度的 sql 数据库?)
如果您想保持点/点精度,您应该考虑将乘数作为 int 存储在不同的表中,并将其与您的汇率对相关联。
首先,将系列重铸为浮动,然后执行您的操作。
c1_preds_data["final_price "] = c1_preds_data["final_price "].astype('float')
c1_preds_data['adjustment'] = c1_preds_data['adjustment'].astype('float')
看起来您正在开发并行回测器。祝你好运!
| 归档时间: |
|
| 查看次数: |
8794 次 |
| 最近记录: |