title: Python: Write values from a CSV-file into a postgresql database
body: <p>I have made a python-script that takes an excel-file, converts it into a csv-file. My problem is that I have several null values in my csv that needs to be null, but as I try to insert it into the database, I get this error</p>
  
  <pre><code>psycopg2.DataError: invalid input syntax for type date: "None"
  LINE 1: ...', 'Some info here', 'And some more', '1995-09-06', 'None'
  </code></pre>
  
  <p>This is the code I written to convert excel-files into a CSV</p>
  
  <pre><code>def excel_to_csv():
      xlsx = pd.read_excel(excel_path + fileName + '.xlsx')
      xlsx.to_csv(csv_file, encoding='utf-8', index=False, na_rep=None, quoting=csv.QUOTE_NONE)
  
  
      excel_to_csv()
  </code></pre>
  
  <p>And when I check the CSV-file, everything is formatted correctly, with values seperated by , and the null value is None, without quotation marks. It seems like the problem start when I try to read the CSV-file and then inserting it into the database. I use csv.reader for this</p>
  
  <pre><code>with open(csv_file, 'rb') as f:
      reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
      next(reader)
      for row in reader:
          cur.execute(
              "INSERT INTO databasetable (foo, foo2, foo3, foo4) VALUES (%s, %s, %s, %s);",
              row
          )
  </code></pre>
  
  <p>Does anyone know whats wrong here?</p>