我正在使用下面的命令從sqlite數據庫中檢索一定數量的數據,並按預期方式獲得一個大的結果列表,同時也導出到HTML和文本文檔。我想根據'messages.conversation_id'列拆分文檔中顯示的表格,但無法找到這樣做的方法。我嘗試過使用groupby函數,但它只是對結果列表進行排序。分割Sqlite數據庫python查詢結果
謝謝。
connect = sqlite3.connect(sqlitedb)
df = pd.read_sql_query("""SELECT messages._id, messages.date, messages.body, messages.conversation_id, participants_info.number, participants_info.display_name, participants_info._id
FROM messages
INNER JOIN participants_info
ON messages.participant_id = participants_info._id;""", connect)
df.to_html(open('messages.html', 'w'))
base_filename = 'test.txt'
with open(os.path.join(base_filename),'w') as outfile:
df.to_string(outfile)
print (df)
我已經表明我下面給出的結果的截圖,我想能夠表分成基礎上,conversation_id柱較小。所以我爲每個ID有不同的表格。