title: How can I associate panda's csv column "type" with mysql column "type" (read below)
body: <p>I am creating an application where I import some csv file and &quot;append&quot; its data to an existing MySQL db table using pandas and sqlalchemy. Now the problem is that there could be some new columns in the csv file which dont exist in the mysql db and in order to add the data in that scenario, I need to first do something like <code>Alter table &lt;tableName&gt; add newcolumn &lt;type&gt;</code> and then  something like <code>df.to_sql('&lt;tableName&gt;', conn, if_exists='append', index=False)</code>. My question is that is there any way I can associate the data type of the columns from panda and accordingly alter the table while adding the columns. Like I know there is something called <code>df.dtypes</code> but this returns things like <code>int64, object</code> which we can’t use as a &lt;<strong>type</strong>&gt; in <code>Alter table ExtractedData add newcolumn &lt;type&gt;</code>  since mysql wont understand it. So, is there any generic way of doing it. I think it might be a simple solution and I searched a lot but I just cant figure this out?</p>
  <p>This is what I am doing right now(pesudocode) -</p>
  <pre><code>...
  
  # creating an engine with sqlalchemy
  engine = create_engine(database_url, max_overflow=0)
  
  # Using Pandas to read the csv file
  df = pd.read_csv('file.csv',sep=',')
  df.columns = df.columns.str.replace(' ', '')
  columns = list(df.columns)
  
  # Connecting with the engine
  with engine.connect() as conn, conn.begin():
      # getting the current column names in the mysql table and storing it as array in header_arr
      headers = list(conn.execute(f&quot;SHOW COLUMNS from tablename&quot;))
      header_arr = []
      for header in headers:
          header_arr.append(header[0])
      # getting the columns in the csv file
      for column in columns:
          if column not in header_arr:
               # create a new column with that 'column' name
               conn.execute(f&quot;ALTER TABLE ExtractedData ADD {column} &lt;type????&gt;&quot;) &lt;--- how to figure out which &lt;type&gt; i need to use here??
      df.to_sql('ExtractedData', conn, if_exists='append', index=False)   
  </code></pre>
  <p>Please let me know if this question needs any more clarity. Thanks for the help :)</p>