Copy a dataframe to postgresql database within a schema

252 views
Skip to first unread message

Nahum Castro

unread,
Feb 23, 2022, 1:54:54 PM2/23/22
to sqlal...@googlegroups.com
Hello All.

I have a problem when I try to load a dataframe to postgresql and store it in a schema..

from msilib import schema
import pandas as pd
import numpy as np
import glob
from sqlalchemy import create_engine
from datetime import datetime, timedelta

engine = create_engine('postgresql://nahum:inifedal@localhost:5432/dbwork')

archivos2=(glob.glob("/Users/nahumcastro/Documents/mdt_work_files/records.csv"))
df_telcel = pd.DataFrame(archivos2)
for index, row in df_telcel.iterrows():
datastore=pd.read_csv(str(row[0]), delimiter=',')
datastore.to_sql('records', engine, schema='work')

The problem that I have is that it asks for a library (msilib) available only on windows.

If I do not use schema 'work' to store only in public schema  there is no problem at all.

/usr/local/bin/python3 /Users/nahumcastro/Documents/load.py
Traceback (most recent call last):
  File "/Users/nahumcastro/Documents/load.py", line 1, in <module>
    from msilib import schema
ModuleNotFoundError: No module named 'msilib'

I am on a macintosh computer.
python 3.9.10
pandas is 1.4.1
sqlalchemy is 1.4.29

Thanks in advance for any help.
Nahum

--
Nahum Castro González
Blvd. Perdigón 214, Brisas del Lago.
CP 37207
León, Guanajuato, México

Mike Bayer

unread,
Feb 23, 2022, 2:34:49 PM2/23/22
to noreply-spamdigest via sqlalchemy
the "from msilib import schema" import is at the top of your script. it looks like it's there by accident.  are you using vscode?  I find it often adds random package names as it guesses from my typing.  I'd remove that line.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.

Nahum Castro

unread,
Feb 23, 2022, 8:59:49 PM2/23/22
to sqlal...@googlegroups.com
Yes, you were right.

thanks.

Reply all
Reply to author
Forward
0 new messages