Python Store变量,有两个列到使用SQLite创建的表格

发布于 2025-01-25 07:12:07 字数 656 浏览 3 评论 0原文

我创建了一个存储患者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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坚持沉默 2025-02-01 07:12:07

您写道,这两个变量是类型文本中的,

c.execute("""CREATE TABLE IF NOT EXISTS PatientNoShow ("PatientId" text, "No-show" text)""")

但是pt_counts包含整数,因为它计算列中的值ateragy> ateragyed,除了.executemany()需要A 序列才能正常工作。

如果ateragyId是字符串类型:该代码应起作用:

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

You wrote that the two variables are of type text in

c.execute("""CREATE TABLE IF NOT EXISTS PatientNoShow ("PatientId" text, "No-show" text)""")

but pt_counts contains integers because it counts the values in the column PatientId, besides .executemany() needs a sequence to work properly.

This piece of code should work if PatientId is of string type:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文