pandas to_sql不处理nan
我只是想发送到Sybase ASE ASE一些包含NAN的浮点数据,预期的结果是数据库中的零。 Pandas版本为1.3.5,Python Python 3.8.12和Sqlalchemy 1.4.28。
表的创建:
create table test(head VARCHAR(20) NOT NULL, val FLOAT NULL, primary key(head))
数据框的创建:
df = pd.DataFrame({"head":["A","B","C"], "val":[1.2,np.nan,42.0]}) #math.nan gets the same result
现在崩溃的代码:
df.to_sql("test",
con = engine,
if_exists="replace",
index=False,
dtype={'head': db.types.VARCHAR(20), 'val': db.types.FLOAT},
chunksize=1)
错误消息:
[SAP][ASE ODBC Driver][Adaptive Server Enterprise]Implicit conversion from datatype 'VARCHAR' to 'FLOAT' is not allowed. Use the CONVERT function to run this query.
对发生的事情有任何想法吗?我到处看,似乎应该像魅力一样工作!
I'm just trying to send to sybase ASE some float data containing nan, the expected result being a NULL in the database.
The pandas version is 1.3.5, and python Python 3.8.12, and sqlalchemy 1.4.28 .
Creation of the table:
create table test(head VARCHAR(20) NOT NULL, val FLOAT NULL, primary key(head))
Creation of the dataframe:
df = pd.DataFrame({"head":["A","B","C"], "val":[1.2,np.nan,42.0]}) #math.nan gets the same result
And now the code that crashes :
df.to_sql("test",
con = engine,
if_exists="replace",
index=False,
dtype={'head': db.types.VARCHAR(20), 'val': db.types.FLOAT},
chunksize=1)
the error message:
[SAP][ASE ODBC Driver][Adaptive Server Enterprise]Implicit conversion from datatype 'VARCHAR' to 'FLOAT' is not allowed. Use the CONVERT function to run this query.
Any idea about what's happening? Everywhere I looked, it seemed like this ought to work like a charm!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论