title: How to create .sql file as output from python dataframe
body: <ul>
  <li><p>The work I have done so far -
  I read all the excel files from directories, edit them as I wish to and create df table</p>
  </li>
  <li><p>The works I need to do -
  My final goal is to create .sql file in current directory. It contains the lines of 1) create the db and tables if they do not exist. 2) Insert the data from the df I have created so that I can import that result sql file. (No connecting directly to my db using pymysql.connect)</p>
  </li>
  </ul>
  <p>My question is that the works I need to do are really generatable? If so, how? I had the thoughts of how to do it as following:</p>
  <ol>
  <li>f= open(&quot;result.sql&quot;,&quot;w+&quot;) to create result .sql file</li>
  <li>f.write for each lines of statements for creating db and tables</li>
  <li>INSERT the data from each column of df to each column of db tables</li>
  </ol>
  <p>Please help me that I'm doing it right or if not, how can it be done.</p>
  <p>Many Thanks</p>
  <p><strong>Edit</strong>: Since there is possibility that I run my program at computer with no internet connection, I want to avoid the methods that connects to my db from there.</p>
  <p>For more details, I need to give this program to someone else. That person runs the program, get the output(.sql file) and give that .sql file to me so that I can import .sql file and get all the data I want to get.</p>
  <p>I tried the suggestion <strong>to_sql</strong> and it was not what I wanted, but instead, I had another thought of just simple use INSERT and SELECT. Another problem is whether I can insert the right data to right columns in db.</p>
  <p>For example, I have dataframe</p>
  <pre><code>df = pd.DataFrame([[1, 2, 3, 4], [1, 3, 13, 4, 5], [4, 6]], columns=['A', 'B', 'C', 'D', 'E'])
  
  
      A   B   C   D   E
  0   1   2   3.0 4.0 NaN
  1   1   3   13.0    4.0 5.0
  2   4   6   NaN NaN NaN
  </code></pre>
  <p>and I want to put Column A,B and E only <strong>select columns by column name</strong></p>