LoginSignup
3
3

More than 5 years have passed since last update.

PythonでSQLiteを使用する方法

Last updated at Posted at 2016-10-02

sqlite3を使って、connectをつくるだけ。
とてもかんたん。


#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

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3