12-23-2022, 11:25 AM
import pyodbc
import pandas as pd
# Connect to the ClickHouse database
conn = pyodbc.connect(
'Driver={ClickHouse ODBC Driver};'
'Server=localhost;'
'Port=9000;'
'Database=mydatabase;'
'UID=user;'
'PWD=password'
)
# Create a cursor
cursor = conn.cursor()
# Execute a SELECT statement to retrieve data from a table
cursor.execute('SELECT * FROM mytable')
# Fetch the rows from the cursor and create a DataFrame
df = pd.DataFrame.from_records(cursor.fetchall())
# Close the cursor and connection
cursor.close()
conn.close()
# Print the DataFrame
print(df)
import pandas as pd
# Connect to the ClickHouse database
conn = pyodbc.connect(
'Driver={ClickHouse ODBC Driver};'
'Server=localhost;'
'Port=9000;'
'Database=mydatabase;'
'UID=user;'
'PWD=password'
)
# Create a cursor
cursor = conn.cursor()
# Execute a SELECT statement to retrieve data from a table
cursor.execute('SELECT * FROM mytable')
# Fetch the rows from the cursor and create a DataFrame
df = pd.DataFrame.from_records(cursor.fetchall())
# Close the cursor and connection
cursor.close()
conn.close()
# Print the DataFrame
print(df)