example_df = [[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]]
我想将example_df pandas数据框集成到现有的Reportlab表中 - 其中行数正在变化(可以是3,如示例中所示,或者它可以是20):
rlab_table(['Mean','Max','Min','TestA','TestB'],
['','','','',''],
['','','','',''],
['','','','','']])
我试过了:
np.array(example_df).tolist()
但我得到这个错误(AttributeError:'int'对象没有属性'wrapOn')
我也尝试过:
inputDF = example_df.loc[:,'col1':'col5']
rlab_table(['Mean','Max','Min','TestA','TestB'],
inputDF)
并且只显示数据框的标题,而不是包含在其中的数据(即使我打印inputDF时我可以看到列出的所有数据)。
我可以通过执行以下操作手动将每行添加到报表实验室表中:
rlab_table(['Mean','Max','Min','TestA','TestB'],
np.array(example_df).tolist()[0],
np.array(example_df).tolist()[1],
np.array(example_df).tolist()[2]])
但是,问题是数据框中的行数不断变化,所以我正在寻找类似于以下的解决方案:
rlab_table(['Mean','Max','Min','TestA','TestB'],
np.array(example_df).tolist()[0:X])]
#Where X is the number of rows in the dataframe
rlab_table = [[ '平均数', '最大值', '最小值', '种皮', 'TESTB']] + df.values.tolist()
在括号外添加数据框列表(如上面的粗体区域)是问题的解决方案(超快!)