无法将 SQL 数据读入 ReportLab 行

Unable to read SQL data into a ReportLab rows

我正在这里做一个报告实验室项目,其中的数据是从 SQlite3 table 读取的。它无法读取并将其转换为供系统读取和 post 的正确格式。最初我从一个有效的 csv 文件中调用了数据。我不会table 以正确的格式呈现此内容以提高性能。

str_rankings = (self.choose_class_combo.currentText() + ' ' + self.choose_term_combo.currentText() + ' ' + self.choose_year_combo.currentText() + ' ' + " STREAM RANKINGS.pdf")
pdf2=SimpleDocTemplate(str_rankings)
frame1 = Frame(30,20,900,600)
land = PageTemplate(id='l',pagesize=[950,650],frames=[frame1])
heading = self.choose_class_combo.currentText()+' '+self.choose_term_combo.currentText()+' '+self.choose_year_combo.currentText()+' OVERALL PERFOMANCE AND GRADE BREAKDOWN'
descrip = ParagraphStyle('description',fontName='Courier-Bold',fontSize=18,leading=30, alignment=TA_CENTER)
head_text = Paragraph(heading,descrip)
pdf.addPageTemplates([land])
pdf2.addPageTemplates(PageTemplate(id='l',pagesize=[950,650],frames=[frame1]))
flow_obj=[]
flow_obj.append(head_text)
#creating the connection
conn = sqlite3.connect('mydb.db')
cur = conn.cursor()
str_summary = pd.read_sql("select * from '" + str(overall_summary) + "'", conn)
with open(str_summary) as f1:
    csvdata=csv.reader(f1,delimiter=",")
    tdata=[]
    for data in csvdata:
        rowdata=[]
        BLANK=data[0]
        A1 =data[1]
        A2=data[2]
        B3=data[3]
        B4=data[4]
        B5=data[5]
        C6=data[6]
        C7=data[7]

它抛出这个错误

Traceback (most recent call last):
  File "D:\Python\PyQt5\Backup\Result Management System(RMS)\REMARE 2.py", line 2084, in get_results
    with open(str_summary) as f1:
TypeError: expected str, bytes or os.PathLike object, not DataFrame

您不能尝试打开 Pandas 数据框或尝试使用 csv.reader() 读取它。如果您想将结果转储到 CSV 文件,请使用 str_summary.to_csv() (to_csv documentation). Otherwise, you can iterate over rows of the DataFrame using iterrows()

举例如下:

for index, row in str_summary.iterrows():
    BLANK = row['column_name']
    A1 = row['another_column_name']
    ...