首页 > 解决方案 > 将 Webscraped 数据绘制到 matplotlib 上

问题描述

我最近设法使用 python 中的 camelot 从 PDF 文件中收集表格数据。通过收集我的意思是在终端上打印出来,现在我想找到一种方法将结果自动转换为 matplotlib 上的条形图。我该怎么做?这是我从pdf中提取表格数据的代码:

import camelot 

tables = camelot.read_pdf("data_table.pdf", pages='2')

print(tables[0].df)

这是表格的 图像 在此处输入图像描述

然后在我的终端中打印出一张大表:

                                                    0          1       2    3     4
0   Country \nCase definition \nCumulative cases \...
1                                              Guinea  Confirmed    2727  156  1683
2                                                       Probable     374    *   374
3                                                      Suspected       7    *     ‡
4                                                          Total    3108  156  2057
5                                           Liberia**  Confirmed    3149   11     ‡
6                                                       Probable    1876    *     ‡
7                                                      Suspected    3982    *     ‡
8                                                          Total    9007   11  3900
9                                        Sierra Leone  Confirmed    8212  230  3042
10                                                      Probable     287    *   208
11                                                     Suspected    2604    *   158
12                                                         Total   11103  230  3408
13                                              Total             23 218  397  9365

我确实对 matplotlib 有一些经验,并且我知道如何手动绘制数据,但不能从 pdf 中自动绘制数据。这会节省我一些时间,因为我正在尝试自动化整个过程。

标签: matplotlibpdfweb-scrapingautomation

解决方案


推荐阅读