【发布时间】:2022-01-07 23:34:25
【问题描述】:
我正在查询一个 API 并从中提取我需要的数据。然后我想将其转换为 pandas 数据框,但不确定最好的方法。我有一些可行但非常复杂的东西。下面的示例数据是一个字典,但这确实来自 API,但它明白了这一点。
invoice_header = {
"VendorName" : "spinxy tester",
"VendorAddress" :"Unit 1 Anglesey Business Park argyle",
"CustomerName": "brick and mortar tavern",
"CustomerId": "73014207",
"CustomerAddress": "112 Main Street",
"CustomerAddressRecipient": "brick and mortar tavern",
"InvoiceId": "57953",
"InvoiceDate": "None",
"InvoiceTotal": "3474.0"
}
InvoiceNumber = "R20140.pdf"
all_invoices = {}
for key, value in invoice_header.items():
all_invoices[key] = value
all_invoices
df = pd.DataFrame(list(all_invoices.items()))
df = df.transpose()
df.columns = df.iloc[0]
df.drop(df.index[0], inplace=True)
【问题讨论】: