I am very very new to Python and the problem i have might be very easy for python pro's.
I am working on an assignment in which there is a part which is :
Create an Audit table in which row is inserted when all the tables are loaded with timestamp.
import pandas as pd
df = pd.DataFrame(data,columns=['Load Status','Updated Timestamp']) . -- Creating data frame to apply logic
df_.to_sql("Audit Table ", conn, if_exists="replace", index=False) -- creating table into database.
Not sure how to tackle it or what is the right approach to achieve it.
This is homework, as such, it is best for you to make your best effort THEN post asking questions about what you are having trouble with.
Thanks for replying.
It would have been easy for me to tackle it in 'non-python' world. As i already mentioned , i am pretty new in this
and wanted to know the approach (not the solution).
Only reason i was prompted to this forum was to get some direction and it seems i am in wrong forum.
(Feb-21-2020, 08:14 PM)pynewbie Wrote: [ -> ]Only reason i was prompted to this forum was to get some direction and it seems i am in wrong forum.
It's difficult to address vague questions. "Create an Audit table..." Perhaps you know what that means within the context of your course, but I don't. Does it require Pandas? What
exactly is your assignment? We prefer code attempts to what I'm asking for here, and I'm not sure where your code falls into that, since I'm not clear on the requirements.
Here's my attempt at explanation and
again i am very very new to Python :
Assignment : Read the csv files and load the data into tables in postgres database.
Code for reading and loading the files into postgres tables is working.(utilized pandas , numpy , sqlalchemy )
Requirement : Need to account whether the script ran fine and all tables got loaded.
One approach that i had was to come up with an Audit table that has name of the table ,load_status and load_date.
there are 12 tables. If the count is greater than 0 for each table , meaning table got loaded with records.
conn = create_engine ("postgresql://<id>:<password>@hostname:port/databasename")
cur = conn.cursor() #to execute select statements
cur.execute (""" CREATE TABLE Audit ( table_name text , Load_status text , load_date date)""")
cur.execute("Select * from table1")
results_table1 = cursor.fetchall()
for r in results_table1:
if results_table1 > 0: [b][i]## I am not sure how to achieve it.[/i][/b]
then INSERT_QUERY = { "INSERT INTO Audit VALUES {}".format("(table1name" ,'Successful' ,'02-24-2020')")
cur.execute(INSERT_QUERY)
## also i have to check it for all 12 tables
I am not sure whether this is correct approach
Also any other suggestions to achieve the requirement stated above is appreciated.
Thanks !