I'm trying to add data frame information to PostgreSQL's table.
But I don't know how to create an engine. It's very likely related to connection to SQL server, but I could not figure out how to create it.
The example I saw on the to_sql document is:
>>> from sqlalchemy import create_engine
>>> engine = create_engine('sqlite://', echo=False)
And what I tried is:
param_dic = {'host': 'localhost', 'database':'databasename', 'user':'username', 'password':'password' }
conn = pgsql.connect(**param_dic)
cursor = conn.cursor()
for filename in work_dir.glob('excel_filename.xlsx'):
df = pd.read_excel(filename)
df.to_sql('table name', conn, if_exists='replace')
conn.commit()
cursor.close()