def df_to_html_table(df, color='white', df_img_col_indexs=[-1]): """df转化为html表格输出, 简单的columns为[txt, img] df : 数据源 color : background df_img_col_indexs : list ,img字段的col索引, 一般放在最后几个字段, 因此里面的值只能是负值 return: str html""" assert (np.max(df_img_col_indexs) < 0) page = pyh.PyH('report') mytab = page << pyh.table() for i in range(len(df)): mytr = mytab << pyh.tr(style="background-color:%s" % (color)) v = df.iloc[i][:np.min(df_img_col_indexs)] if v.name == 0 and len(v.tolist()) == 1: v = v[0] s = str(v) if not agl.is_utf8(s): #命令行时会碰到需要转码的情况 try: s = s.decode('gb2312').encode('utf8') except: pass mytr << pyh.td('<pre>%s</pre>' % (s)) for j in df_img_col_indexs: mytr << pyh.td('Row %i, column <img src="%s"/>' % (i, os.path.basename(df.iloc[i][df.columns[j]]))) return page.render()
def drawDf(pl, df, title=''): pl.figure if title != '': if agl.is_utf8(title): title = title.decode('utf8') #pl.title(title, fontproperties=getFont()) if not isinstance(df, type(None)): pl.rc('font', family='simhei') df.plot(title=title) pl.show() pl.close()
def drawTwoDf(pl, df1, df2, title=''): """分别画两个df""" pl.figure pl.rc('font', family='simhei') if title != '': if agl.is_utf8(title): title = title.decode('utf8') fig = pl.gcf() ax1 = fig.add_subplot(211) df1.plot(ax=ax1, title=title) ax2 = fig.add_subplot(212) df2.plot(ax=ax2) pl.show() pl.close()