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)类型时间戳的无效输入语法:"23:37.2“行1:...75,140.89,75.92,0.0,0.0,0.0,0.0,0.0,NULL,'23:37.2',.
也许它把它当作字符串,也许这就是它显示错误的原因。
在导入postgresql之前,是否有任何选项可以代替在我的csv中更改它?
发布于 2020-09-22 14:09:53
错误告诉您问题:
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
您的数据没有提供足够的信息作为时间戳使用。为了更清楚一点,如果只提供时间,则需要更改表字段的类型。或者,如果将其保留为时间戳,则需要创建完整的时间戳(日期和时间)。
https://stackoverflow.com/questions/64010102
复制相似问题