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' object has no attribute '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
1 回答

幕布斯7119047
TA贡献1794条经验 获得超8个赞
rlab_table=[['Mean','Max','Min','TestA','TestB']] +df.values.tolist()
在括号外添加数据框列表(如上面的粗体区域)是解决问题的方法(而且速度超快!)
添加回答
举报
0/150
提交
取消