Skip to main content

Pass postgres data to pandas dataframe

Project description

Install

pip install justogres

Usage

1. Create client object

psql = clientPsql(
        host = <your host>,
        user = <your user>,
        password = <your password>,
        port=<your port (optional)>,
        db_name=<your database name>,
    )

2. execute query or insert method

2.1 exec_query()

psql.exec_query(
    <your sql query>,
    chunksize = <chunksize (optional)>)

if query return something, method return pandas.Dataframe object

2.2 insert() -> return None

psql.insert(
    <your pd.DataFrame object>,
    table_name=<your table name>, #if doesn't exist, will be created
    schema=<your schema name>, #should be created previously
    chunksize=<your chunksize to load (default: 1000)>)

Examples:

first we must init client

psql = clientPsql(
        host = os.environ.get("host_justo_pg"),
        user = os.environ.get("username_justo_pg"),
        password = os.environ.get("password_justo_pg"),
        port=os.environ.get("port_justo_pg"),
        db_name='postgres',
    )

Then follow this options:

1.if we are gona execute query

q="""DELETE 
    FROM schema_name.table_name 
    WHERE column_name='value';"""
psql.exec_query(q)

1.1 (special case) if we are gonna read

q="""SELECT * 
    FROM schema_name.table_name;"""
df = psql.read(q)

2. if we are gonna insert

df = pd.read_csv('example.csv')
psql.insert(
    df,
    table_name='test_table',
    schema='test_schema',
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

justogres-3.0.0.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

justogres-3.0.0-py3-none-any.whl (4.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page