发生了例外:typeError' nattype'对象不可呼应

发布于 2025-02-12 13:27:35 字数 1123 浏览 0 评论 0原文

我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜点 2025-02-19 13:27:35

错误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 part dataFrame['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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文