将数据框值导入字典

Import Data frame value to Dictionary

我有一个代码可以从 pdf 中提取 table 数据,我想将数据框转换为字典,如果我在表格中提到输出为 JSON 它也会给出坐标这不是必需的。我只想要 table 中的数据。如果将数据框转换为字典,我可以进行其他处理工作

from tabula import read_pdf
from tabulate import tabulate
import pandas as pd

df = read_pdf("http://www.uncledavesenterprise.com/file/health/Food%20Calories%20List.pdf",multiple_tables=True,pages='3' ,pandas_options={'header':None},guess = False)
print (df)

您可以使用 df.to_dict() 将数据框转换为字典。您可以直接使用此方法,也可以提供一些参数,这些参数可以分别检查 here for pandas v1.0.5 or here for pandas v0.23.4 . You can also use df.to_json() for converting the dataframe to JSON. Information regarding arguments can be found here and here for v1.0.5 和 v0.23.4。