pandas.DataFrame.to_sql
pandas 3.1.1 · DataFrame · method
Write tabular data to a SQL table. Use if_exists to control what happens when the table is already present.
Call syntax
DataFrame.to_sql(…) Full signature
DataFrame.to_sql(
name,
con,
*,
schema=None,
if_exists='fail',
index=True,
index_label=None,
chunksize=None,
dtype=None,
method=None,
)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
name |
Required Positional or keyword |
str Set a name or identify the named object used by the operation. |
con |
Required Positional or keyword |
ADBC connection, sqlalchemy.engine.(Engine or Connection) or sqlite3.Connection Provide a database connection or supported SQLAlchemy connectable. |
schema |
Optional Keyword only Default None |
str Provide the schema defining the field names and types. |
if_exists |
Optional Keyword only Default 'fail' |
{'fail', 'replace', 'append', 'delete_rows'} Set how a database write handles an already existing table. |
index |
Optional Keyword only Default True |
bool Supply row labels or control how existing row labels are used. |
index_label |
Optional Keyword only Default None |
str or sequence Choose the column heading written for row index values. |
chunksize |
Optional Keyword only Default None |
int Set how many rows to read or write in each batch. |
dtype |
Optional Keyword only Default None |
dict or scalar Choose the data type for the input conversion or result. |
method |
Optional Keyword only Default None |
{None, 'multi', callable} Choose the algorithm used to calculate, align, or fill the result. |
Returns
None or int