@@ -908,6 +908,33 @@ def to_msgpack(self, path_or_buf=None, **kwargs):
908
908
from pandas .io import packers
909
909
return packers .to_msgpack (path_or_buf , self , ** kwargs )
910
910
911
+ def to_sql (self , name , con , flavor = 'sqlite' , if_exists = 'fail' , index = True ):
912
+ """
913
+ Write records stored in a DataFrame to a SQL database.
914
+
915
+ Parameters
916
+ ----------
917
+ name : string
918
+ Name of SQL table
919
+ con : SQLAlchemy engine or DBAPI2 connection (legacy mode)
920
+ Using SQLAlchemy makes it possible to use any DB supported by that
921
+ library.
922
+ If a DBAPI2 object is given, a supported SQL flavor must also be provided
923
+ flavor : {'sqlite', 'mysql'}, default 'sqlite'
924
+ The flavor of SQL to use. Ignored when using SQLAlchemy engine.
925
+ Required when using DBAPI2 connection.
926
+ if_exists : {'fail', 'replace', 'append'}, default 'fail'
927
+ - fail: If table exists, do nothing.
928
+ - replace: If table exists, drop it, recreate it, and insert data.
929
+ - append: If table exists, insert data. Create if does not exist.
930
+ index : boolean, default True
931
+ Write DataFrame index as a column
932
+
933
+ """
934
+ from pandas .io import sql
935
+ sql .to_sql (
936
+ self , name , con , flavor = flavor , if_exists = if_exists , index = index )
937
+
911
938
def to_pickle (self , path ):
912
939
"""
913
940
Pickle (serialize) object to input file path
0 commit comments