-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.py
55 lines (44 loc) · 1.02 KB
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#%%
import pandas as pd
import sqlite3
from PIL import Image
#%%
def add_sqlite_table(db,tablename, pk, not_null, column_order):
table=db.table(
tablename,
pk=pk,
not_null=not_null,
column_order=column_order
)
# %%
def sql_to_pandas(db, sql_command,):
'''turns sqlite database into a pandas dataframe'''
conn= sqlite3.connect(db)
sql= sql_command
data = pd.read_sql(sql, conn)
return data
# %%
def get_image(path:str)->Image:
image = Image.open(path)
return image
#%%
def delete_all_sql(conn, sql):
"""
Delete all rows in the tasks table
:param conn: Connection to the SQLite database
:return:
"""
sql = sql
cur = conn.cursor()
cur.execute(sql)
conn.commit()
#%%
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by the db_file
:param db_file: database file
:return: Connection object or None
"""
conn = sqlite3.connect(db_file)
return conn
# %%