Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read data from clickhouse database using python?
#1
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)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)