How to use SQLite in Python

Just make a connect using sqlite3. Very easy.


#codeing:UTF-8

import sqlite3
import pandas as pd

#If not, a new one will be created
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)

#Don't forget to commit
con.commit()

check_sql = """
select * from gas_portal_access_log
"""
df = pd.read_sql(check_sql,con)
con.close

print df

Recommended Posts

How to use SQLite in Python
How to use Mysql in python
How to use ChemSpider in Python
How to use PubChem in Python
[Introduction to Python] How to use class in Python?
How to use __slots__ in Python class
How to use regular expressions in Python
How to use is and == in Python
python3: How to use bottle (2)
[Python] How to use list 1
How to use Python argparse
Python: How to use pydub
[Python] How to use checkio
How to develop in Python
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
How to use the C library in Python
How to use Python Image Library in python3 series
Summary of how to use MNIST in Python
How to use tkinter with python in pyenv
How to handle datetime type in python sqlite3
[For beginners] How to use say command in python!
[Python] How to do PCA in Python
Python: How to use async with
How to use classes in Theano
[Python] How to use Pandas Series
How to collect images in Python
[Python] How to use list 3 Added
How to use OpenPose's Python API
How to wrap C in Python
How to use FTP with Python
Sqlite in python
Python: How to use pydub (playback)
I tried to summarize how to use pandas in python
How to use the model learned in Lobe in Python
How to use python zip function
How to handle Japanese in Python
[Python] How to use Typetalk API
How to use the __call__ method in a Python class
[Introduction to Udemy Python 3 + Application] 36. How to use In and Not
Comparison of how to use higher-order functions in Python 2 and 3
How to use calculated columns in CASTable
[Python] Summary of how to use pandas
How to access environment variables in Python
How to dynamically define variables in Python
How to install and use pandas_datareader [Python]
How to do R chartr () in Python
[Itertools.permutations] How to put permutations in Python
How to use Google Test in C
[python] How to use __command__, function explanation
How to work with BigQuery in Python
[Python] How to use import sys sys.argv
How to get a stacktrace in python
How to display multiplication table in python
Easy way to use Wikipedia in Python
How to extract polygon area in Python
[Python] Organizing how to use for statements