我試圖從我的數(shù)據(jù)庫(kù)中提取數(shù)據(jù)并將其放入可以在 chart.js 中顯示的格式。我使用 python,我的數(shù)據(jù)庫(kù)使用 sqlite3。我設(shè)法從表中提取必要的值并以表格格式打印出來進(jìn)行檢查,但我不確定從這里去哪里。from os import mkdirimport sqlite3try: conn = sqlite3.connect('foldername/db.sqlite')except sqlite3.OperationalError: mkdir('foldername')finally: conn = sqlite3.connect('foldername/db.sqlite')cursor = conn.cursor()room_no = 1cursor.execute( "SELECT room, strftime( '%H:00', date ) AS HOUR, SUM(count) AS DENSITY FROM crowd WHERE strftime('%Y-%m-%d', date) = strftime('%Y-%m-%d','now') AND room = ? group by HOUR order by HOUR asc",(room_no,))for row in cursor: print('{0} : {1}, {2}'.format(row[0], row[1], row[2]))cursor.close()conn.close()為了澄清,輸出當(dāng)前打印如下:1 : 09:00, 31 : 10:00, 41 : 11:00, -21 : 12:00, 11 : 13:00, 11 : 14:00, 1但我需要將不同的列放入這樣的數(shù)組中:['09:00','10:00','11:00',...][3, 4, -2,...]有什么建議么?
使用 Python 將 SQL 表中的列保存到數(shù)組中
慕尼黑8549860
2022-11-09 17:26:03