title: How can I copy data from CSV into QuestDB using Python?
body: <p>I'm using the psychopg2 module to make queries against QuestDB from Python. I have had some trouble using the <a href="https://www.psycopg.org/docs/usage.html#using-copy-to-and-copy-from" rel="nofollow noreferrer">copy_from()</a> cursor object to get CSV data into a table. What's the best way to get this into the database?</p>
  <p>I'm trying the following:</p>
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  import numpy as np
  import psycopg2
  import os
  
  conn = psycopg2.connect(user=&quot;admin&quot;,
                                password=&quot;quest&quot;,
                                host=&quot;127.0.0.1&quot;,
                                port=&quot;8812&quot;,
                                database=&quot;qdb&quot;)
  
  cursor = conn.cursor()
  
  dest_table = &quot;eur_fr_bulk&quot;
  temp_dataframe = &quot;./temp_dataframe.csv&quot;
  
  # input
  df = pd.read_csv(&quot;./data/eur_fr.csv&quot;)
  df.to_csv(temp_dataframe, index_label='id', header=False)
  
  f = open(temp_dataframe, 'r')
  
  cursor = conn.cursor()
  try:
      cursor.copy_from(f, dest_table)
      conn.commit()
  except (Exception, psycopg2.DatabaseError) as error:
      os.remove(temp_dataframe)
      print(&quot;Error: %s&quot; % error)
      conn.rollback()
      cursor.close()
  
  cursor.close()
  </code></pre>