Last active
October 2, 2016 12:13
Star
You must be signed in to star a gist
PythonでSQLiteを使用する方法 ref: http://qiita.com/tadaken3/items/4fae3d19ef07b95f82cf
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
#codeing:UTF-8 | |
import sqlite3 | |
import pandas as pd | |
#ない場合は新たに作成される | |
con = sqlite3.connect('/Users/Desktop/web_data.db') | |
drop_table = "drop table gas_portal_access_log" | |
create_table = """ | |
create table gas_portal_access_log ( | |
user text, | |
pv integer, | |
page_id text | |
); | |
""" | |
insert_table = """ | |
insert into gas_portal_access_log values('yamada taro',3 ,'1234'); | |
""" | |
insert2_table = """ | |
insert into gas_portal_access_log values('hoge',2 ,'1234'); | |
""" | |
con.execute(drop_table) | |
con.execute(create_table) | |
con.execute(insert_table) | |
con.execute(insert2_table) | |
#コミットを忘れず | |
con.commit() | |
check_sql = """ | |
select * from gas_portal_access_log | |
""" | |
df = pd.read_sql(check_sql,con) | |
con.close | |
print df | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment