Python Store变量,有两个列到使用SQLite创建的表格
我创建了一个存储患者ID的变量,并计算了每位患者错过的约会数量。我创建了一个使用SQLITE的表,并且正在尝试将变量存储到创建的表中,但是我遇到了“ ValueRorr:参数是不支持的类型”的错误。到目前为止,这是我的代码:
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”的答案将不胜感激!另外,一旦我创建了表格并将信息存储在其中,我将如何打印或获得输出的视觉效果?
I created a variable that stores patient ID and a count of the number of missed appointments per patient. I created a table with SQLite and I am trying to store my variable into my created table but I am getting an error of "ValueError: parameters are of unsupported type". Here is my code so far:
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)
Thank you in advance for any help! Still learning, so any kind of "explain to me like I'm 5" answers will be appreciated! Also, once I create my tables and store info in them, how would I print or get a visual of the output?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您写道,这两个变量是类型文本中的,
但是
pt_counts
包含整数,因为它计算列中的值ateragy> ateragyed
,除了.executemany()需要A 序列才能正常工作。
如果
ateragyId
是字符串类型:该代码应起作用:You wrote that the two variables are of type text in
but
pt_counts
contains integers because it counts the values in the columnPatientId
, besides.executemany()
needs a sequence to work properly.This piece of code should work if
PatientId
is of string type: