-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbtocsv.py
More file actions
41 lines (38 loc) · 1 KB
/
Copy pathdbtocsv.py
File metadata and controls
41 lines (38 loc) · 1 KB
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
import sqlite3
import pandas as pd
# Open the file
f = open('out.csv', 'w')
# Create a connection and get a cursor
connection = sqlite3.connect('maliciousness.db')
cursor = connection.cursor()
# Execute the query
cursor.execute('select * from ENCRYPTION')
# Get Header Names (without tuples)
colnames = [desc[0] for desc in cursor.description]
# Get data in batches
while True:
# Read the data
df = pd.DataFrame(cursor.fetchall())
# We are done if there are no data
if len(df) == 0:
break
# Let us write to the file
else:
df.to_csv(f, header=colnames)
cursor.execute('select * from PREDICTIONS')
# Get Header Names (without tuples)
colnames = [desc[0] for desc in cursor.description]
# Get data in batches
while True:
# Read the data
df = pd.DataFrame(cursor.fetchall())
# We are done if there are no data
if len(df) == 0:
break
# Let us write to the file
else:
df.to_csv(f, header=colnames)
# Clean up
f.close()
cursor.close()
connection.close()