Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Import CSV to QuestDB from Python
import urllib.request
import pandas as pd
import requests
def import_data(file_name, table_name):
params = {}
params['timestamp'] = 'TradeDate'
params['partitionBy'] = 'MONTH'
url_values = urllib.parse.urlencode(params)
query_url = "http://%s:9000/imp?" % (server_ip) + url_values
df = pd.read_csv(file_name, sep=",")
df.drop_duplicates(subset=None, inplace=True)
df.to_csv(file_name, index=False)
with open(file_name, 'rb') as csv:
file_data = csv.read()
files = {'data': (table_name, file_data)}
schema = '[{"name":"TradeDate", "type": "TIMESTAMP", "pattern": "yyyy-MM-dd" }]'
response = requests.post(query_url, data={'schema': schema}, files=files)
print(response.text)
server_ip = '127.0.0.1'
import_data('my_data.csv', 'test_import')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment