字典到数据框,列名不正确

时间:2019-05-06 12:29:18

标签: json pandas

我正在调用rest api,并将响应转换为字典,如下所示(例如,我得到了更多物品):

{
  "page": 1,
  "pages": 1,
  "limit": 100,
  "total": 20,
  "items": [
    {
      "address": {
        "salutation": 0,
        "personal": false,
        "title": null,
        "first_name": "Max",
        "last_name": "Mustermann",
        "suffix_1": null,
        "suffix_2": null,
        "company_name": null,
        "street": "Musterstr.",
        "zip_code": null,
        "city": "Musterstadt",
        "country": "DE"
      },
      "attachment_ids": [],
      "label_address": {
        "salutation": 0,
        "personal": false,
        "title": null,
        "first_name": "Max",
        "last_name": "Mustermann",
        "suffix_1": null,
        "suffix_2": null,
        "company_name": null,
        "street": "Musterstr.",
        "zip_code": null,
        "city": "Musterstadt",
        "country": "DE"
      },
      "amount": 0,
      "amount_net": 0,
      "bank_debit_form": null,
      "billing_country": null,
      "calc_vat_from": 0,
      "cancel_id": null,
      "cash_allowance": null,
      "cash_allowance_days": null,
      "cash_allowance_text": null,
      "contact_id": null,
      "contact_label": "",
      "contact_text": "",
      "created_at": "2019-02-01 11:16:52",
      "currency": "EUR",
      "customer_id": null,
      "customer_snapshot": {
        "acquire_options": null,
        "bank_account": null,
        "bank_account_owner": null,
        "bank_bic": null,
        "bank_code": null,
        "bank_iban": null,
        "bank_name": null,
        "birth_date": "2016-12-31",
        "cash_allowance": null,
        "cash_allowance_days": 7,
        "cash_discount": null,
        "cash_discount_type": null,
        "city": "Kaarst",
        "company_name": "easybill GmbH",
        "country": "DE",
        "created_at": "string",
        "updated_at": "string",
        "delivery_city": null,
        "delivery_company_name": null,
        "delivery_country": null,
        "delivery_first_name": null,
        "delivery_last_name": null,
        "delivery_personal": false,
        "delivery_salutation": 0,
        "delivery_street": null,
        "delivery_suffix_1": null,
        "delivery_suffix_2": null,
        "delivery_zip_code": null,
        "display_name": "string",
        "emails": [
          "max.mustermann@easybill.de"
        ],
        "fax": "+49 2154 89701 29",
        "first_name": "Max",
        "grace_period": null,
        "due_in_days": null,
        "group_id": null,
        "id": 0,
        "info_1": null,
        "info_2": null,
        "internet": "https://www.easybill.de",
        "last_name": "Mustermann",
        "login_id": 0,
        "mobile": null,
        "note": null,
        "number": "string",
        "payment_options": null,
        "personal": false,
        "phone_1": "+49 2154 89701 20",
        "phone_2": null,
        "postbox": null,
        "postbox_city": null,
        "postbox_country": null,
        "postbox_zip_code": null,
        "sale_price_level": null,
        "salutation": 0,
        "sepa_agreement": null,
        "sepa_agreement_date": null,
        "sepa_mandate_reference": null,
        "since_date": null,
        "street": "Düsselstr. 21",
        "suffix_1": null,
        "suffix_2": null,
        "tax_number": null,
        "tax_options": null,
        "title": null,
        "vat_identifier": "DE814878557",
        "zip_code": "41564"
      },
      "discount": null,
      "discount_type": null,
      "document_date": "2019-02-07",
      "due_date": null,
      "edited_at": "2019-02-07 11:54:10",
      "external_id": null,
      "replica_url": null,
      "grace_period": null,
      "due_in_days": null,
      "id": 0,
      "is_archive": false,
      "is_draft": true,
      "is_replica": false,
      "items": [
        {
          "number": null,
          "description": null,
          "quantity": 1,
          "quantity_str": null,
          "unit": null,
          "type": "POSITION",
          "position": null,
          "single_price_net": null,
          "single_price_gross": 0,
          "vat_percent": 0,
          "discount": null,
          "discount_type": null,
          "position_id": null,
          "total_price_net": 0,
          "total_price_gross": 0,
          "total_vat": 0,
          "serial_number_id": null,
          "serial_number": null,
          "booking_account": null,
          "export_cost_1": null,
          "export_cost_2": null,
          "cost_price_net": null,
          "cost_price_total": null,
          "cost_price_charge": null,
          "cost_price_charge_type": null,
          "itemType": "UNDEFINED",
          "id": 0
        }
      ],
      "last_postbox_id": null,
      "login_id": null,
      "number": null,
      "paid_amount": 0,
      "paid_at": null,
      "pdf_pages": 0,
      "pdf_template": null,
      "project_id": null,
      "recurring_options": {
        "next_date": "2020-02-01",
        "frequency": "MONTHLY",
        "frequency_special": null,
        "interval": 1,
        "end_date_or_count": null,
        "status": "WAITING",
        "as_draft": false,
        "is_notify": false,
        "send_as": null,
        "is_sign": false,
        "is_paid": false,
        "is_sepa": false,
        "sepa_local_instrument": null,
        "sepa_sequence_type": null,
        "sepa_reference": null,
        "sepa_remittance_information": null
      },
      "ref_id": null,
      "service_date": {
        "type": "DEFAULT",
        "date": "2019-02-01",
        "date_from": null,
        "date_to": null,
        "text": null
      },
      "shipping_country": null,
      "status": null,
      "text": "Vielen Dank für Ihren Auftrag!\\n\\nBitte begleichen Sie den offenen Betrag bis zum %DOKUMENT.DATUM-FAELLIG%.\\n\\nMit freundlichen Grüßen\\n\\n%FIRMA.FIRMA%\\n",
      "text_prefix": "%KUNDE.ANREDE%,\\nnachfolgend berechnen wir Ihnen wie vorab besprochen:\\n",
      "title": "Invoice for Order #001",
      "type": "INVOICE",
      "use_shipping_address": false,
      "vat_country": null,
      "fulfillment_country": null,
      "vat_option": null
    }
  ]
} 

当我尝试将此字典转换为熊猫数据框时,我的df看起来像 RangeIndex:23个条目,0到22 数据列(共5列): 项目23非空对象 限制23非null int64 第23页非null int64 第23页非null int64 总共23个非null int64 dtypes:int64(4),对象(1) 内存使用率:992.0+字节 没有

是否有可能将嵌套信息也从项目中提取到额外的列中?

谢谢! E。

0 个答案:

没有答案