Python中SQL Server的阅读日期列中使用Pymssql软件包的问题
我在SQL Server表中有一个日期列(TRNDATE),该表像DB
2021-11-29 09:48:05.0000000 +04:00
在Jupyter Notebook中读取此内容,我正在使用Pymsssql package。我的代码在下面的结果集下方看起来像是这样,
import pymssql
import pandas as pd
import datetime as datetime
conn = pymssql.connect(server, user, password, "HecPoll5")
df = pd.read_sql_query('select * from dbo.v_beeah_data where customerid=379691', conn )
print(df)
但是我在日期中获得十六进制字符的输出(以粗体标记)。
tid ----数字----- trndate ----- livemandatorId ----数量---- customerId
63221 ---- 731 ---- b'\ x00 $ \ xd5 \ xffb \ XFFB \ x00 \ x00 \ x00 \ x00 \ xbc \ xae \ xae \ x00 \ x00 \ x00 \ x00 \ x ... ---- 1 ---- 80.0 ---- 379691
我尝试添加
parse_dates = {“ trndate”:“%y%m%d%h:%m:%m:%s”}& parse_dates = true read_sql_query &在 Connect 中,添加charset =“ UTF-8”参数,到目前为止还没有任何效果。
这是我第一次使用此库,除了日期列外,结果集中的所有其他列都很好。如果有人以前遇到过这样的问题,请帮助我在这里缺少的东西。
I have a date column (trnDate) in an SQL Server Table, which is stored like this in DB
2021-11-29 09:48:05.0000000 +04:00
To read this in Jupyter Notebook, I am using the pymssql package. My code looks like this below
import pymssql
import pandas as pd
import datetime as datetime
conn = pymssql.connect(server, user, password, "HecPoll5")
df = pd.read_sql_query('select * from dbo.v_beeah_data where customerid=379691', conn )
print(df)
The result set however gives me the output where i get hex characters in my dates (marked in bold).
TID----Number----trnDate----LiveMandatorID----Quantity----CustomerID
63221----731----b'\x00$\xd5\xffB\x00\x00\x00\xbc\xae\x00\x00\x...----1----80.0----379691
I have tried adding
parse_dates={"trnDate":"%Y%m%d %H:%M:%S"} &
parse_dates=True in read_sql_query & adding charset="UTF-8" parameters in connect as well, nothing have so far worked well.
This is the first time I am using this library, all other columns in the result set works well except the date column. If anyone has previously encountered such issue, kindly help with what I am missing here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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