我創建了一個變數來存盤患者 ID 和每位患者錯過的預約次數。我用 SQLite 創建了一個表,我試圖將我的變數存盤到我創建的表中,但我收到“ValueError:引數型別不受支持”的錯誤。到目前為止,這是我的代碼:
import pandas as pd
import sqlite3
conn = sqlite3.connect('STORE')
c = conn.cursor()
c.execute("DROP TABLE IF EXISTS PatientNoShow")
c.execute("""CREATE TABLE IF NOT EXISTS PatientNoShow ("PatientId" text, "No-show" text)""")
df = pd.read_csv(r"C:\missedappointments.csv")
df2 = df[df['No-show']=="Yes"]
pt_counts = df2["PatientId"].value_counts()
c.executemany("INSERT OR IGNORE INTO PatientNoShow VALUES (?, ?)", pt_counts)
預先感謝您的任何幫助!仍在學習,所以任何型別的“像我 5 歲一樣向我解釋”答案將不勝感激!此外,一旦我創建了我的表并在其中存盤資訊,我將如何列印或獲得輸出的視覺效果?
uj5u.com熱心網友回復:
您寫道,這兩個變數的型別為 text in
c.execute("""CREATE TABLE IF NOT EXISTS PatientNoShow ("PatientId" text, "No-show" text)""")
但pt_counts包含整數,因為它計算列中的值PatientId,此外還.executemany()需要一個序列才能正常作業。
PatientId如果是字串型別,這段代碼應該可以作業:
import pandas as pd
import sqlite3
conn = sqlite3.connect('STORE')
c = conn.cursor()
c.execute("DROP TABLE IF EXISTS PatientNoShow")
c.execute("""CREATE TABLE IF NOT EXISTS PatientNoShow ("PatientId" text, "No-show" integer)""") # type changed
df = pd.read_csv(r"C:/Users/bob/Desktop/Trasporti_project/Matchings_locations/norm_data/standard_locations.csv")
pt_counts = df["standard_name"].value_counts()
c.executemany("INSERT OR IGNORE INTO PatientNoShow VALUES (?, ?)", pt_counts.iteritems()) # this is a sequence
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/470351.html
下一篇:動態記憶體分配與使用指標
