-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecond.py
More file actions
69 lines (56 loc) · 1.71 KB
/
Copy pathsecond.py
File metadata and controls
69 lines (56 loc) · 1.71 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sqlite3
import webbrowser
from pyecharts.charts import Bar
from pyecharts import options as opts
def select_data():
"""
查询数据库中数据分析的历史记录
:return 包含查询结果的列表
"""
# 连接到SQLite
# 参数为数据库文件名称
# 返回值:数据库连接对象
conn = sqlite3.connect('data_analyze.db')
# 创建一个游标对象,用于执行SQL语句等操作
cursor = conn.cursor()
# 查询
sql = 'SELECT * FROM beauty;'
cursor.execute(sql)
rows = cursor.fetchall() # 拿到所有查询的结果
# # 遍历输出每行数据
for row in rows:
print(row) # 返回值元组
# 关闭游标和连接
cursor.close()
conn.close()
return rows
def draw_bars(rows):
"""
画柱状图
:param rows: 列表套元组,每个人的数据是一个元组对象
:return: 生成的网页
"""
# 不习惯链式调用的开发者依旧可以单独调用方法
bar = Bar() # 创建一个柱状图对象
# 添加x轴
bar.add_xaxis(['无人脸', '1', '2', '3', '4',
'5', '6', '7', '8', '9', '10'])
# 遍历rows
for row in rows:
# 取出keyword
keyword = row[2]
# 切片取出颜值分布数据
y_axis = list(row)[3:]
print(keyword, y_axis)
# 添加y轴
bar.add_yaxis(keyword, y_axis)
# 设置标题
bar.set_global_opts(title_opts=opts.TitleOpts(title="历史数据对比"))
# 生成网页,参数为网页名称
file_name = '历史查询.html'
bar.render(file_name)
return file_name
if __name__ == '__main__':
rows = select_data()
file = draw_bars(rows)
webbrowser.open(file)