-
Notifications
You must be signed in to change notification settings - Fork 0
create_table(tname: str, df: pd.DataFrame, if_exists='fail')
Marcel Ferrari edited this page Feb 9, 2023
·
1 revision
Creates a new table in the database with the contents of a Pandas DataFrame.
create_table(tname: str, df: pd.DataFrame, if_exists='fail') -> None
-
tname
: name of the new table. -
df
: Pandas DataFrame containing the data to be inserted into the new table. -
if_exists
: What to do if the table already exists. Possible values arefail
,replace
, andappend
.fail
raises an error,replace
deletes the existing table and creates a new one, andappend
inserts the data into the existing table.
# Connect to the database
db = PandaSQLiteDB("example.sql")
# Create a Pandas DataFrame
df = pd.DataFrame({
'column1': [1, 2, 3],
'column2': ['A', 'B', 'C']
})
# Create a new table named "my_table" in the database
db.create_table('my_table', df)