· 8 years ago · Dec 09, 2017, 02:18 PM
1import sqlite3
2from pandas.io import sql
3# Create your connection.
4cnx = sqlite3.connect('mydbfile.sqlite')
5
6# read the result of the SQL query into a DataFrame
7data = sql.read_sql("SELECT * FROM data;", cnx)
8
9# now you can write it into a HDF5 file
10data.to_hdf('test_store.hdf','test',mode='w')
11
12import sqlite3
13conn=sqlite3.connect("Employee.db")
14cur=conn.cursor()
15
16
17def mymeth():
18cur.execute('CREATE TABLE IF NOT EXISTS Employee ("emp_name" TEXT, "emp_phone" INT,"job_title" TEXT, "dept_name" TEXT, "emp_salary" INT, "place" TEXT)')
19
20
21def insert():
22cur.execute('INSERT INTO Employee VALUES ("Mantice",9876543210,"CEO","Company",85000,"Australia")')
23cur.execute('INSERT INTO Employee VALUES ("Panda",9876543211,"Chairman","Company",65000,"Europe")')
24cur.execute('INSERT INTO Employee VALUES ("Tingu",9876543212,"General Manager","Marketing",55000,"Japan")')
25cur.execute('INSERT INTO Employee VALUES ("Puhi",9876543213,"HR","Interview",45000,"Africa")')
26conn.commit()
27
28
29def display():
30cur.execute(' SELECT * from Employee')
31for row in cur.fetchall():
32 print(row)
33
34
35def sum_sal():
36cur.execute("SELECT SUM(emp_salary) from Employee")
37for row in cur.fetchone():
38 print(row)
39
40
41
42
43mymeth()
44insert()
45sum_sal()
46display()