【发布时间】:2021-10-28 22:11:12
【问题描述】:
我将我的数据框转换为 json 类型:
df_json = df.to_json(orient = "records")
但是通过这种方式,我的 NaN 列被转换为 None,而我实际上希望它们是 NaN。因此,当我将我的数据帧继续到 postgres 时,NaN 列将被读取并提取为 NULL。
我转换数据框时的结果:
no type
1 All
2 None
3 None
同时,想要的结果:
no type
1 All
2 NaN
3 NaN
到目前为止,我已经尝试过:
df_json = df.to_json(orient = "records").replace("None", np.NaN)
但我收到错误replace() argument 2 must be str, not float
如何将None 转换为 NaN?
提前致谢。
【问题讨论】: