Examples
Create an in-memory SQLite database:

In [1]:
import numpy as np
import pandas as pd
In [2]:
from sqlalchemy import create_engine
engine = create_engine('sqlite://', echo=False)

Create a table from scratch with 3 rows:

In [3]:
df = pd.DataFrame({'name' : ['User P', 'User Q', 'User R']})
df
Out[3]:
name
0 User P
1 User Q
2 User R
In [4]:
df.to_sql('users', con=engine)
engine.execute("SELECT * FROM users").fetchall()
Out[4]:
[(0, 'User P'), (1, 'User Q'), (2, 'User R')]
In [5]:
df1 = pd.DataFrame({'name' : ['User S', 'User T']})
df1.to_sql('users', con=engine, if_exists='append')
engine.execute("SELECT * FROM users").fetchall()
Out[5]:
[(0, 'User P'), (1, 'User Q'), (2, 'User R'), (0, 'User S'), (1, 'User T')]

Overwrite the table with just df1.

In [6]:
df1.to_sql('users', con=engine, if_exists='replace',
           index_label='id')
engine.execute("SELECT * FROM users").fetchall()
Out[6]:
[(0, 'User S'), (1, 'User T')]

Specify the dtype:

In [7]:
df = pd.DataFrame({"X": [2, None, 3]})
df
Out[7]:
X
0 2.0
1 NaN
2 3.0
In [8]:
from sqlalchemy.types import Integer
df.to_sql('integers', con=engine, index=False,
          dtype={"X": Integer()})
In [9]:
engine.execute("SELECT * FROM integers").fetchall()
Out[9]:
[(2,), (None,), (3,)]