发生了例外:typeError' nattype'对象不可呼应
我使用Python数据框将数据从数据湖传输到GP Envt。我有一个具有数据类型“ DateTime”的列。
import psycopg2
import pandas as pds
from sqlalchemy import create_engine
alchemyEngine = create_engine('postgresql+psycopg2://user_name:Host:5432/warehouse')
dbConnection = alchemyEngine.connect()
script = '''SELECT name,lastrun_date FROM Table'''
dataFrame = pds.read_sql(script, dbConnection)
dbConnection.close()
conn= psycopg2.connect(host = hostname,
dbname = database,
user = username,
password = pwd,
port = port_id)
curr=conn.cursor()
for i in dataFrame.index:
script_insert = '''insert into Schema.destination_table
(name,last_run)
values (%s,%s)'''
val = (str(dataFrame['name'][i]), str(dataFrame['parsed_ts'][i]))
curr.execute(script_insert,val)
conn.commit()
conn.close()
获取错误
“对象无法callable”
。我尝试替换str(dataframe ['parsed_ts'] [i])
用str(dataframe ['parsed_ts'] [i] [i]('%y-%y-%y-%d%h :%m:%s'))
它引发错误:异常发生:typeError'nattype'对象不可呼应
I use a python dataframe to transfer the data from the data lake to GP envt. I have a column with the data type "DateTime".
import psycopg2
import pandas as pds
from sqlalchemy import create_engine
alchemyEngine = create_engine('postgresql+psycopg2://user_name:Host:5432/warehouse')
dbConnection = alchemyEngine.connect()
script = '''SELECT name,lastrun_date FROM Table'''
dataFrame = pds.read_sql(script, dbConnection)
dbConnection.close()
conn= psycopg2.connect(host = hostname,
dbname = database,
user = username,
password = pwd,
port = port_id)
curr=conn.cursor()
for i in dataFrame.index:
script_insert = '''insert into Schema.destination_table
(name,last_run)
values (%s,%s)'''
val = (str(dataFrame['name'][i]), str(dataFrame['parsed_ts'][i]))
curr.execute(script_insert,val)
conn.commit()
conn.close()
Getting the error
"object is not callable"
. I have tried replacing str(dataFrame['parsed_ts'][i])
WITH str(dataFrame['parsed_ts'][i]('%Y-%m-%d %H:%M:%S'))
It throws the error: Exception has occurred: TypeError 'NaTType' object is not callable
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误
typeerror'nattype'对象不会出现
出现,因为您试图将null值称为函数。在行
str中(dataframe ['parsed_ts'] [i]('%y-%m-%d%h:%m:%m:%s'))
,零件dataframe [ 'parsed_ts'] [i]
正在返回零值,您正在尝试访问其属性('%y-%m-%d%h:%m:%m:%s')
,,这是错误的。如果您想更改时间戳的格式,请尝试先处理空值,然后用 datetime.strptime和/或datetime.strftime ,根据数据集中的数据的显示方式。The Error
TypeError 'NaTType' object is not callable
appears because you are trying to call a null value as a function.In the line
str(dataFrame['parsed_ts'][i]('%Y-%m-%d %H:%M:%S'))
, the partdataFrame['parsed_ts'][i]
is returning a null value and you are trying to access its property('%Y-%m-%d %H:%M:%S')
, which is wrong. If you want to transform the format of your timestamps, try handling the null values first and then wrangling the timestamps with datetime.strptime and/or datetime.strftime, according to how the data is presented in your dataset.