title: How to write Pandas dataframe to sqlite with Index
body: <p>I have a list of stockmarket data pulled from Yahoo in a pandas DataFrame (see format below). The date is serving as the index in the DataFrame. I want to write the data (including the index) out to a SQLite database. </p>
  
  <pre><code>             AAPL     GE
  Date
  2009-01-02  89.95  14.76
  2009-01-05  93.75  14.38
  2009-01-06  92.20  14.58
  2009-01-07  90.21  13.93
  2009-01-08  91.88  13.95
  </code></pre>
  
  <p>Based on my reading of the write_frame code for Pandas, it <a href="https://github.com/pydata/pandas/blob/master/pandas/io/sql.py#L163">does not currently support writing the index</a>. I've attempted to use to_records instead, but ran into the <a href="https://github.com/pydata/pandas/issues/1908">issue with Numpy 1.6.2 and datetimes</a>. Now I'm trying to write tuples using .itertuples, but SQLite throws an error that the data type isn't supported (see code and result below). I'm relatively new to Python, Pandas and Numpy, so it is entirely possible I'm missing something obvious. I think I'm running into a problem trying to write a datetime to SQLite, but I think I might be overcomplicating this. </p>
  
  <p>I think I <em>may</em> be able to fix the issue by upgrading to Numpy 1.7 or the development version of Pandas, which has a fix posted on GitHub. I'd prefer to develop using release versions of software - I'm new to this and I don't want stability issues confusing matters further. </p>
  
  <p>Is there a way to accomplish this using Python 2.7.2, Pandas 0.10.0, and Numpy 1.6.2? Perhaps cleaning the datetimes somehow? I'm in a bit over my head, any help would be appreciated. </p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import numpy as np
  import pandas as pd
  from pandas import DataFrame, Series
  import sqlite3 as db
  
  # download data from yahoo
  all_data = {}
  
  for ticker in ['AAPL', 'GE']:
      all_data[ticker] = pd.io.data.get_data_yahoo(ticker, '1/1/2009','12/31/2012')
  
  # create a data frame
  price = DataFrame({tic: data['Adj Close'] for tic, data in all_data.iteritems()})
  
  # get output ready for database export
  output = price.itertuples()
  data = tuple(output)
  
  # connect to a test DB with one three-column table titled "Demo"
  con = db.connect('c:/Python27/test.db')
  wildcards = ','.join(['?'] * 3)
  insert_sql = 'INSERT INTO Demo VALUES (%s)' % wildcards
  con.executemany(insert_sql, data)
  </code></pre>
  
  <p><strong>Result:</strong></p>
  
  <pre><code>---------------------------------------------------------------------------
  InterfaceError                            Traceback (most recent call last)
  &lt;ipython-input-15-680cc9889c56&gt; in &lt;module&gt;()
  ----&gt; 1 con.executemany(insert_sql, data)
  
  InterfaceError: Error binding parameter 0 - probably unsupported type.
  </code></pre>