-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeywords2.py
More file actions
52 lines (49 loc) · 1.55 KB
/
Keywords2.py
File metadata and controls
52 lines (49 loc) · 1.55 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
42
43
44
45
46
47
48
49
50
51
52
def prepareChart(workbook):
global worksheet
chart1 = workbook.add_chart({'type': 'line'})
chart1.add_series({
'name': '=Frequency',
'categories': '=Sheet1!$A$2:$A$24',
'values': '=Sheet1!$B$2:$B$24'
})
chart1.add_series({
'name': '=Density',
'categories': '=Sheet1!$A$2:$A$24',
'values': '=Sheet1!$C$2:$C$24'
})
chart1.set_title ({'name': 'Results of sample analysis'})
chart1.set_x_axis({'name': 'Keywords'})
chart1.set_y_axis({'name': 'Density , Frequency'})
chart1.set_style(10)
worksheet.insert_chart('D2', chart1)
workbook.close()
def writeExcelOutput(cursor):
import xlsxwriter
workbook=xlsxwriter.Workbook('OutputExcel.xlsx')
global worksheet
worksheet=workbook.add_worksheet()
worksheet.write('A1', 'Keyword')
worksheet.write('B1', 'Frequency')
worksheet.write('C1', 'Density')
i=2
print("Keywords - Frequency - Density")
for data in cursor:
print(data[0].ljust(8)," - ",str(data[1]).ljust(8)," - ",data[2])
x='A'+str(i)
y='B'+str(i)
z='C'+str(i)
worksheet.write(x,data[0])
worksheet.write(y,data[1])
worksheet.write(z,data[2])
i=i+1
prepareChart(workbook)
print('Successfully wrote')
worksheet=""
import sqlite3
con=sqlite3.connect('mydb2.db')
print('Database created/connected')
cursor=con.execute('select keyword,count,dens from rec')
writeExcelOutput(cursor)
print("To see the chart open the output excel file")
cursor.close()
con.close()