-
Notifications
You must be signed in to change notification settings - Fork 0
/
df2sql.py
39 lines (28 loc) · 785 Bytes
/
df2sql.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
import pandas as pd
import sqlite3
conn = sqlite3.connect("CoinbaseAPI.sqlite")
# Purpose is to create a table if it doesnt exist
"""
call_df()
Get inital DF
"""
df.to_sql(name="CANDLE_STICK",
con=conn,
if_exists="fail", # "append","replace","fail" default: fail
index=True, # Sets df index to table index
dtype={
"start": "TIMESTAMP PRIMARY KEY",
"open": "REAL",
"high": "REAL",
"low": "REAL",
"close": "REAL",
}
)
"""
call_df()
Appending to that DF
"""
for v in df.iterrows():
conn.execute("INSERT OR REPLACE INTO CANDLE_STICK values (?,?,?,?,?,?)", [str(v[0])] + list(v[1].values))
conn.commit()
print(conn.total_changes)