Last active
December 14, 2017 09:20
-
-
Save kyoro1/eec125e84632c0bca854a5d3d186697f to your computer and use it in GitHub Desktop.
AzureのSQL Serverにテーブルの内容を書き出す ref: https://qiita.com/kyoro1/items/eaa4c136df60373d3501
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install sqlalchemy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## initial setting | |
server = 'abc_server.database.windows.net' | |
database = 'abc_database' | |
username = 'abc_user' | |
password = 'abc_password' | |
def export_sql_sv(DF, TABLE_NAME, username=username, password=password, server=server, database=database): | |
## 接続確認 | |
engine = sqlalchemy.create_engine( | |
'mssql+pyodbc://'+ username +':'+ password + '@' + server + '/' + database + '?driver=SQL+Server+Native+Client+11.0') | |
## SQL DBにDataFrameをexport | |
DF.to_sql(TABLE_NAME, engine, if_exists='replace') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export_sql_sv(df, 'table_abc') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment