将数据从csv导入postgresql时出现时间戳错误


import uuid
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('postgresql+psycopg2://postgres:xxx@localhost:5432/xxxxa')
df=pd.read_csv("uplauds_corp_financial.csv")
li=[]
for _ in range(len(df)):
ud = uuid.uuid1()
print(ud)
li.append(ud)
df['uuid_']=li
df.to_sql(name="uplauds_corp_financial", con=engine, if_exists='append', index=False)

ERROR=sqlalchemy.exc.DataError:(psycopg2.errors.InvalidDatetimeFormat(类型timestamp的无效输入语法:"23:37.2";第1行:。。。75140.89,75.92,0.0,0.0,0.0,0.0,NULL,'23:37.2',…

也许它将其作为字符串,也许这就是它显示错误的原因
有没有任何选项可以代替在我的csv中更改它我可以在导入postgresql之前更改它

在此处输入图像描述

错误告诉您问题:

select '23:37.2'::timestamp;
ERROR:  invalid input syntax for type timestamp: "23:37.2"
LINE 1: select '23:37.2'::timestamp;
#Reformatting won't help
select '23:37:00.2'::timestamp;
ERROR:  invalid input syntax for type timestamp: "23:37:00.2"
LINE 1: select '23:37:00.2'::timestamp;

#Use time type
select '23:37.2'::time;
time    
------------
00:23:37.2

您的数据没有提供足够的信息用作时间戳。为了更清楚一点,如果只提供一个时间,则需要更改表字段的类型。或者,如果将其保留为时间戳,则需要创建一个完整的时间戳(日期和时间(。

最新更新