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=[['Mean','Max','Min','TestA','TestB']]+df.values.tolist()
在括号外添加数据框列表(如上面的粗体区域)是问题的解决方案(而且 super 快!)
关于python - 如何将 pandas 数据框合并到现有的 reportlab 表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54699953/