Reputation: 9
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
Upvotes: 0
Views: 488
Reputation: 307
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.
Upvotes: 0