SteveS
SteveS

Reputation: 4040

How to load data from a connection string with vaex package?

If I have a table on my server and I am producing a connection string to it, how can I, using Vaex, load it to a dataframe?

Here is what I am doing but with Pandas:

from sqlalchemy import types, create_engine, text
import pandas as pd
import pymysql

def connect_to_data(driver='mysql+pymysql://', conn_string=''):
    try:
        conn = create_engine(driver + conn_string)
        print("MySQL Connection Successfull!")
    except Exception as err:
        print("MySQL Connection Failed!")
        print(err)
    return conn

# Connect to the db:
conn_string = 'xxxxxxxx'
conn = connect_to_data(conn_string=conn_string)

# Get all requests from the db:
query = '''SELECT * FROM table_name'''

result = conn.execute(text(query))

# Desired dataframe:
df = pd.read_sql_query(query, conn)

How can I do the same with Vaex (because of it's high performance)?

Upvotes: 0

Views: 1030

Answers (1)

Joco
Joco

Reputation: 813

For now at least, you can't do it directly. But vaex can easily read a pandas dataframe so you can

# Following your example..
pandas_df = pd.read_sql_query(query, conn)

df = vaex.from_pandas(pandas_df)

Upvotes: 2

Related Questions