Example of using SQLAlchemy+Pandas, works with this Cloud SQL as well
from sqlalchemy import create_engine
import pandas as pd
server = '<your-server-hostname>'
port = 1972
namespace = 'USER'
username = 'SQLAdmin'
password = '<YOUR_PASSWORD>'
url = f"iris://{username}:{password}@{server}:{port}/{namespace}"
print(url)
engine = create_engine(url)
df = pd.DataFrame({
'int': [1, 2, 3, 4, 5],
'float': [1.1, 2.2, 3.3, 4.4, 5.5],
'string': ['a', 'b', 'c', 'd', 'e'],
'datetime': pd.date_range('20130101', periods=5),
'bool': [True, False, True, False, True]
})
# create a table in IRIS
df.to_sql('iris_table', engine, if_exists='replace', schema='sqlalchemy')
# read the table back from IRIS
df2 = pd.read_sql_table('iris_table', engine, schema='sqlalchemy')
# print the dataframe
print(df2)- Log in to post comments
.png)