Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Update:</h3> <p>There is now a <a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html" rel="noreferrer"><code>to_sql</code></a> method, which is the preferred way to do this, rather than <code>write_frame</code>:</p> <pre><code>df.to_sql(con=con, name='table_name_for_df', if_exists='replace', flavor='mysql') </code></pre> <p><em>Also note: the syntax may change in pandas 0.14...</em></p> <p>You can set up the connection with <a href="http://mysql-python.sourceforge.net/MySQLdb.html" rel="noreferrer">MySQLdb</a>:</p> <pre class="lang-py prettyprint-override"><code>from pandas.io import sql import MySQLdb con = MySQLdb.connect() # may need to add some other options to connect </code></pre> <p>Setting the <code>flavor</code> of <code>write_frame</code> to <code>'mysql'</code> means you can write to mysql:</p> <pre class="lang-py prettyprint-override"><code>sql.write_frame(df, con=con, name='table_name_for_df', if_exists='replace', flavor='mysql') </code></pre> <p>The argument <code>if_exists</code> tells pandas how to deal if the table already exists:</p> <blockquote> <p><code>if_exists: {'fail', 'replace', 'append'}</code>, default <code>'fail'</code><br> &nbsp;&nbsp;&nbsp;&nbsp; <code>fail</code>: If table exists, do nothing.<br> &nbsp;&nbsp;&nbsp;&nbsp; <code>replace</code>: If table exists, drop it, recreate it, and insert data.<br> &nbsp;&nbsp;&nbsp;&nbsp; <code>append</code>: If table exists, insert data. Create if does not exist.</p> </blockquote> <p><em>Although the <a href="http://pandas.pydata.org/pandas-docs/dev/io.html#sql-queries" rel="noreferrer"><code>write_frame</code> docs</a> currently suggest it only works on sqlite, mysql appears to be supported and in fact there is quite a bit of <a href="https://github.com/pydata/pandas/blob/master/pandas/io/tests/test_sql.py#L223" rel="noreferrer">mysql testing in the codebase</a>.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload