Skip to content

Instantly share code, notes, and snippets.

@tadaken3
Last active October 2, 2016 12:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tadaken3/cac4e95dc6456f13dc8e073e4fdeb947 to your computer and use it in GitHub Desktop.
PythonでSQLiteを使用する方法 ref: http://qiita.com/tadaken3/items/4fae3d19ef07b95f82cf
#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