Skip to content

Instantly share code, notes, and snippets.

@kirlf
Last active December 25, 2020 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirlf/9708e7d5279ab95f1da241b774e307d8 to your computer and use it in GitHub Desktop.
Save kirlf/9708e7d5279ab95f1da241b774e307d8 to your computer and use it in GitHub Desktop.
from datetime import datetime
import pandas as pd
from clickhouse_driver import Client
client = Client('localhost')
db_name = "db_name"
tables_list = ["table_1", "table_2"]
db_table_list = ["{db}.{tb}".format(db=db_name, tb=tb) for tb in tables_list]
for tb in db_table_list:
result = client.execute("SELECT * FROM {tb}".format(tb=tb))
columns = client.execute("DESCRIBE TABLE {tb}".format(tb=tb))
cols = [c[0] for c in columns]
df = pd.DataFrame(result, columns=cols)
df["dt"] = pd.to_datetime(df["dt"], format="%Y-%m-%d")
df["ts"] = pd.to_datetime(df["ts"], format="%Y-%m-%d %H:%M:%S")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment