使用python和pandas,我需要将sql查询的结果以24行为一组分页到一个plotly表中.我该怎么做



我可以从sql查询df=pd.read_sql(sql_query,mynn(创建数据帧,它可以创建plotly表,但我不知道如何只读取数据帧的24行-创建plotlly表将其写入图像,然后在第25行重新启动。plotly表使用cells=dict(values=df.transpose((.values,这很有效。我尝试过将pd函数concat、append等插入到临时数据帧中。我尝试过循环,而循环总是会出错。问题是,如何从sql查询中对pandas数据帧中的一组行进行子集设置,并保留每个子集组的列值?

temp_cursor.execute(sql_query1)
table_rows=temp_cursor.fetchall()
rowcnt=len(table_rows)
table_output=table_rows[0]
row = 1
while row < rowcnt:
table_output.update(table_rows[row])
if row % 24 == 0:
### call picture slide builder
prs=table_slide_builder(awsconn, prs, pres_slide,table_output, orgid, png_file_path,function_name)
row=row+1
if row < rowcnt:
table_output=table_rows[row]
row=row+1
#### this is in case there is any remaining rows count < 24 but will not print a dup slide if table_rows is multiple of 24
if rowcnt % 24 != 0 and rowcnt != 0:
### call  picture slide builder
prs=table_slide_builder(awsconn, prs, pres_slide,table_output, orgid, png_file_path,function_name)
#### in table_slide_builder
cost_ops_24_table_trace = go.Table(
columnwidth=[15]+[15], 
header=dict(values=['<b>Account</b>',
'<b>Region</b>','<b>Resource</b>', '<b>Salary</b>', '<b>Salary Amount</b>','<b>Description</b>'],
fill_color ='#021F5F',
font_family ='Arial',
font_color ='#FFFFFF',
font_size =28,
height =80,
align =['center']
),
cells = dict(values=table_output,
fill_color='rgb(255,255,255)',
font_color='rgb(0,0,0)',
font_family='Arial',
font_size=24,
align=['right']*5,
line = dict(color='#000000'),
height = 40,
line_width=1
)
)
cost_ops_24_layout = go.Layout(width=2450, height=1067, autosize=False)
cost_ops_24_fig = go.Figure(data=[cost_ops_24_table_trace], layout=cost_ops_24_layout)
mytablefile=png_file_path+name_png_file(orgid,function_name,slide.slide_id, placeholderidx)
cost_ops_24_fig.write_image(mytablefile, format='png', scale=1.2, width=2450, height=1067)

最新更新