Full Version: How to read data from clickhouse database using python?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import pyodbc
import pandas as pd

# Connect to the ClickHouse database
conn = pyodbc.connect(
   'Driver={ClickHouse ODBC Driver};'

# 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

# Print the DataFrame