Last active
December 25, 2020 10:06
-
-
Save kirlf/9708e7d5279ab95f1da241b774e307d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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