-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstore.py
executable file
·56 lines (45 loc) · 1.57 KB
/
store.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
56
#! /Users/tsuno/.pyenv/shims/python3
import sqlite3
import pandas as pd
class Store:
########################################################################
# init data
def __init__(self,dbname):
self.dbname = dbname
########################################################################
# make database
def make_table(self,input_file,tablename):
# read csv file by pandas
####################
df = pd.read_csv(input_file)
####################
conn = sqlite3.connect(self.dbname)
#cur = conn.cursor()
df.to_sql(tablename,conn,if_exists='replace',index=None)
conn.close()
########################################################################
# make database
def conv_pd_data(self,df,tablename):
conn = sqlite3.connect(self.dbname)
df.to_sql(tablename,conn,if_exists='replace',index=None)
conn.close()
########################################################################
# read database
def conv_csv(self,tablename,out_file):
conn = sqlite3.connect(self.dbname)
df=pd.read_sql_query('SELECT * FROM %s' % tablename, conn)
print(df)
df.to_csv(out_file,header=True,index=None)
conn.close()
########################################################################
# end of class
"""
dbname = 'TEST.db'
input_file = './tmp.csv'
tablename = 'mp'
out_file = 'tmp000.csv'
st = Store(dbname)
st.make_table(input_file,tablename)
st.conv_csv(tablename,out_file)
print(os.path.dirname(self.showFileDialog()))
"""