使用方括号展平嵌套json(Python Pandas)

ccrfmcuu  于 2023-01-22  发布在  Python
关注(0)|答案(1)|浏览(182)

我想寻求任何关于在括号内规范化JSON的建议。我已经用json_normalize和一个用户定义函数做了几次尝试来拒绝任何JSON,到目前为止,这些都毫不费力地工作着(感谢Serge de Gosson de Varennes的分享,谢谢!),但我总是遇到错误,或者用户定义的函数没有扁平化下面的JSON数据。
下面是CSV示例

total_count,start_index,items,items_per_page,filing_history_status
14750,0,"[{'category': 'capital', 'date': '2023-01-18', 'description': 'capital-return-purchase-own-shares', 'links': {'self': '/company/00102498/filing-history/MzM2NjI2NjAwOGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/KFIPMRklI9VLmGnwmLTteT757IXrdIXEweOGPopDAtc'}, 'paper_filed': True, 'type': 'SH03', 'annotations': [{'annotation': 'Clarification hmrc confirmation duty paid', 'category': 'annotation', 'date': '2023-01-18', 'description': 'annotation', 'description_values': {'description': 'Clarification hmrc confirmation duty paid'}, 'type': 'ANNOTATION'}], 'pages': 3, 'barcode': 'ABVEZEGG', 'transaction_id': 'MzM2NjI2NjAwOGFkaXF6a2N4'}, {'category': 'capital', 'date': '2023-01-18', 'description': 'capital-return-purchase-own-shares', 'links': {'self': '/company/00102498/filing-history/MzM2NjI2NjAwNGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/Vnn3SQ93Bjt1i9j0bbte52sVb9GA5gbT9P7J8RRy35I'}, 'paper_filed': True, 'type': 'SH03', 'pages': 5, 'barcode': 'ABVEZEEG', 'transaction_id': 'MzM2NjI2NjAwNGFkaXF6a2N4'}, {'action_date': '2023-01-10', 'category': 'capital', 'date': '2023-01-17', 'description': 'capital-sale-or-transfer-treasury-shares-with-date-currency-capital-figure', 'description_values': {'capital': [{'currency': 'USD', 'figure': '251,229,378', 'date': '2023-01-10'}], 'date': '2023-01-10'}, 'links': {'self': '/company/00102498/filing-history/MzM2NTYyMDc0NmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/kn0cgguEz1QENk-MUsFXRcLUSaUkcc2ds4dLJxRVLDg'}, 'paper_filed': True, 'type': 'SH04', 'pages': 2, 'barcode': 'YBV5MT5S', 'transaction_id': 'MzM2NTYyMDc0NmFkaXF6a2N4'}, {'action_date': '2022-12-23', 'category': 'capital', 'date': '2023-01-17', 'description': 'capital-sale-or-transfer-treasury-shares-with-date-currency-capital-figure', 'description_values': {'capital': [{'currency': 'USD', 'figure': '251,022,732.5', 'date': '2022-12-23'}], 'date': '2022-12-23'}, 'links': {'self': '/company/00102498/filing-history/MzM2NTYyMTIxMmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/9P23zv_wuYQkXdRMEbyDv5wbLM9b06hqGtfOXGyeHPE'}, 'paper_filed': True, 'type': 'SH04', 'pages': 2, 'barcode': 'YBV5MVAI', 'transaction_id': 'MzM2NTYyMTIxMmFkaXF6a2N4'}, {'category': 'capital', 'date': '2023-01-12', 'description': 'capital-return-purchase-own-shares', 'links': {'self': '/company/00102498/filing-history/MzM2NTQzMzkxMmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/EgbaDfsLiwXqwi-w5Hus-QKPdcI1kYmjrTOoLJmiI_4'}, 'paper_filed': True, 'type': 'SH03', 'annotations': [{'annotation': 'Clarification HMRC confirmation received that appropriate duty has been paid on this repurchase.', 'category': 'annotation', 'date': '2023-01-12', 'description': 'annotation', 'description_values': {'description': 'Clarification hmrc confirmation received that appropriate duty has been paid on this repurchase.'}, 'type': 'ANNOTATION'}], 'pages': 3, 'barcode': 'ABUTWG01', 'transaction_id': 'MzM2NTQzMzkxMmFkaXF6a2N4'}, {'category': 'capital', 'date': '2023-01-12', 'description': 'capital-return-purchase-own-shares', 'links': {'self': '/company/00102498/filing-history/MzM2NTQzMzkxMWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/t0ey0FXW0kaaTi9P8Ps-5zM95IG3iTkM3fTHJK2b6dI'}, 'paper_filed': True, 'type': 'SH03', 'annotations': [{'annotation': 'Clarification HMRC confirmation received that appropriate duty has been paid on this repurchase.', 'category': 'annotation', 'date': '2023-01-12', 'description': 'annotation', 'description_values': {'description': 'Clarification hmrc confirmation received that appropriate duty has been paid on this repurchase.'}, 'type': 'ANNOTATION'}], 'pages': 3, 'barcode': 'ABUTWFZU', 'transaction_id': 'MzM2NTQzMzkxMWFkaXF6a2N4'}, {'action_date': '2022-12-22', 'category': 'capital', 'date': '2023-01-09', 'description': 'capital-allotment-shares', 'description_values': {'date': '2022-12-22', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'currency': 'USD', 'figure': '4,760,695,780.25'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2NTAyOTczNGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/XJE1I-VE224cxMQKzzJFSs6hTPS0X0edMLFe2y8ViEU'}, 'type': 'SH01', 'pages': 4, 'barcode': 'XBUUT623', 'transaction_id': 'MzM2NTAyOTczNGFkaXF6a2N4'}, {'action_date': '2022-10-20', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-20', 'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,866,938,331.50', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTgwMWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/WOIUjTKXXPVduvRy3kkNfq6jiwU6fTZPmFAyq9Tc6k8'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXNZF', 'transaction_id': 'MzM2MzUwMTgwMWFkaXF6a2N4'}, {'action_date': '2022-11-07', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-11-07', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,841,613,617', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjMzN2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/vGcWIhrp2T51Xjwvh-DxGZG2s-qX0pee3-uyvVdhq-s'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXQ7U', 'transaction_id': 'MzM2MzUwMjMzN2FkaXF6a2N4'}, {'action_date': '2022-11-08', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,839,188,723.50', 'currency': 'USD'}], 'date': '2022-11-08'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjMzOGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/hX4_Z1O_rV2y6hrqQrxs9qIWNOhTwBlDajSien0XGjM'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXQ83', 'transaction_id': 'MzM2MzUwMjMzOGFkaXF6a2N4'}, {'action_date': '2022-10-26', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,855,749,979.50', 'currency': 'USD'}], 'date': '2022-10-26'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0MWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/esS-R31w94VMTfbEvz1ak5wBWK-dZta5rzlTu6BMTQc'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPGJ', 'transaction_id': 'MzM2MzUwMjE0MWFkaXF6a2N4'}, {'action_date': '2022-10-28', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-28', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'currency': 'USD', 'figure': '4,850,257,261'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0NWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/tvtkhuXRyEhqol5f-NDu1b5D93tykfMTfIJQDWr_iyE'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPBU', 'transaction_id': 'MzM2MzUwMjE0NWFkaXF6a2N4'}, {'action_date': '2022-11-04', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-11-04', 'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'currency': 'USD', 'figure': '4,843,953,910.25'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0OWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/rJTbehtmiovQhzX625TilsiLBPLN0BtTQcQQPQyTz2g'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPCI', 'transaction_id': 'MzM2MzUwMjE0OWFkaXF6a2N4'}, {'action_date': '2022-10-31', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,847,654,519', 'currency': 'USD'}], 'date': '2022-10-31'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0OGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/vnZ4v6xLe61-aj509lCrSZyrciGWfd3JYArL0pJk-h0'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPC2', 'transaction_id': 'MzM2MzUwMjE0OGFkaXF6a2N4'}, {'action_date': '2022-10-25', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-25', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'currency': 'USD', 'figure': '4,858,505,435.25'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjAwNmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/NBMwIr_YjIXCPunxhAZDmZyKXFnMgvC-UCbEPIQYkQA'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXOMA', 'transaction_id': 'MzM2MzUwMjAwNmFkaXF6a2N4'}, {'action_date': '2022-11-03', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'currency': 'USD', 'figure': '4,846,406,664.25'}], 'date': '2022-11-03'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0N2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/JlVWlMQwiT0uw0GsFDi5N3l6YuY6jpLMIIve7Sdxs7c'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPCA', 'transaction_id': 'MzM2MzUwMjE0N2FkaXF6a2N4'}, {'action_date': '2022-10-27', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,852,987,329', 'currency': 'USD'}], 'date': '2022-10-27'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0M2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/pA1ufNYMqxg1IqjVXcFx1v2aVCbu8Tt3HYP2jRezWRc'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPGR', 'transaction_id': 'MzM2MzUwMjE0M2FkaXF6a2N4'}, {'action_date': '2022-10-21', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,864,093,329.75', 'currency': 'USD'}], 'date': '2022-10-21'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjAwM2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/RXHig4q8GhyTAm8n6IQ2adQsYVK6tHOFwvx9j8KJ6dM'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXOKI', 'transaction_id': 'MzM2MzUwMjAwM2FkaXF6a2N4'}, {'action_date': '2022-10-24', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'currency': 'USD', 'figure': '4,861,296,627.75'}], 'date': '2022-10-24'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjAwNWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/Xab3kKnqCQez6IkyCNR98_krrmTSNuR5usQ7ECT9oLY'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXOM2', 'transaction_id': 'MzM2MzUwMjAwNWFkaXF6a2N4'}, {'action_date': '2022-10-14', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,878,250,683.50', 'currency': 'USD'}], 'date': '2022-10-14'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTY0MWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/J3Zv7zI7JWvJJX5SjVruBwthLEgx6KfM7PqRC_ahLnU'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXN37', 'transaction_id': 'MzM2MzUwMTY0MWFkaXF6a2N4'}, {'action_date': '2022-10-18', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-18', 'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,872,592,202.25', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTc5OWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/Bpg0KCk-scjaq6aGkI_XXEi7Hq-ia34Yevn0AZN-x9s'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXNVV', 'transaction_id': 'MzM2MzUwMTc5OWFkaXF6a2N4'}, {'action_date': '2022-10-12', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-12', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,884,232,443.25', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTYzN2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/rtHP4aZ76T2H9ufCF5saoxCTydKp9x-6b62xuyLTLeM'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXN5F', 'transaction_id': 'MzM2MzUwMTYzN2FkaXF6a2N4'}, {'action_date': '2022-10-19', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-19', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,869,745,587.75', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTgwMGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/8wMFoih73gPzsW3cKAEHxpPHcNUUfWRc7_jdJCvJTo4'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXO34', 'transaction_id': 'MzM2MzUwMTgwMGFkaXF6a2N4'}, {'action_date': '2022-10-13', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-13', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,881,240,830.50', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTYzOGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/ugvcHhgmk9x3IthyitanO5Vfk3wRf7q5V366uuMhfcU'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXN6Z', 'transaction_id': 'MzM2MzUwMTYzOGFkaXF6a2N4'}, {'action_date': '2022-10-17', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-17', 'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,875,370,334', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTY0MmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/7qNdyy_cXHh2bD_kNvz6Tx4CCdLrjqZVuIdCo-ytSx0'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXNC8', 'transaction_id': 'MzM2MzUwMTY0MmFkaXF6a2N4'}]",25,filing-history-available
12,0,"[{'action_date': '2022-09-23', 'category': 'confirmation-statement', 'date': '2022-09-30', 'description': 'confirmation-statement-with-no-updates', 'description_values': {'made_up_date': '2022-09-23'}, 'links': {'self': '/company/12098424/filing-history/MzM1MzcxMDIyOWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/wm97CdEs1DD7j6mZuW5lQg1Z9c0OINd9yTIotgAhqtI'}, 'type': 'CS01', 'pages': 3, 'barcode': 'XBDNG7WZ', 'transaction_id': 'MzM1MzcxMDIyOWFkaXF6a2N4'}, {'action_date': '2021-07-31', 'category': 'accounts', 'date': '2022-04-29', 'description': 'accounts-with-accounts-type-total-exemption-full', 'description_values': {'made_up_date': '2021-07-31'}, 'links': {'self': '/company/12098424/filing-history/MzMzNzg3MDQyMGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/4tOH4j8gi_Y20nCkuVkboyhIS6Lzj9hp-5AjXvRCmfE'}, 'type': 'AA', 'pages': 9, 'barcode': 'XB2XP2YY', 'transaction_id': 'MzMzNzg3MDQyMGFkaXF6a2N4'}, {'action_date': '2021-09-23', 'category': 'confirmation-statement', 'date': '2021-10-06', 'description': 'confirmation-statement-with-no-updates', 'description_values': {'made_up_date': '2021-09-23'}, 'links': {'self': '/company/12098424/filing-history/MzMxNjI0Njc4OGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/gejKaHDsYPaEReCs17xJu0zS4PNfMHP43FkjygYeslA'}, 'type': 'CS01', 'pages': 3, 'barcode': 'XAEKJKRD', 'transaction_id': 'MzMxNjI0Njc4OGFkaXF6a2N4'}, {'action_date': '2020-07-31', 'category': 'accounts', 'date': '2021-04-30', 'description': 'accounts-with-accounts-type-total-exemption-full', 'description_values': {'made_up_date': '2020-07-31'}, 'links': {'self': '/company/12098424/filing-history/MzI5OTY1MDE0NGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/G42SZuUKIYaMwqBTv4WFQ_46ITwTCso8JoMQmQBZ-qw'}, 'type': 'AA', 'pages': 9, 'barcode': 'XA3HJGOR', 'transaction_id': 'MzI5OTY1MDE0NGFkaXF6a2N4'}, {'action_date': '2020-09-23', 'category': 'confirmation-statement', 'date': '2020-10-09', 'description': 'confirmation-statement-with-no-updates', 'description_values': {'made_up_date': '2020-09-23'}, 'links': {'self': '/company/12098424/filing-history/MzI4MDA5MDQxMmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/RpF_HoJZui0F68sDrMM3H6hWW66MIevkwtRsGsRoVYg'}, 'type': 'CS01', 'pages': 3, 'barcode': 'X9FAGITS', 'transaction_id': 'MzI4MDA5MDQxMmFkaXF6a2N4'}, {'type': 'CS01', 'action_date': '2019-09-23', 'description_values': {'made_up_date': '2019-09-23'}, 'links': {'self': '/company/12098424/filing-history/MzI0NDg5NDUxM2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/Ekb8A2MZsDtRU7tiVXYx5sXLXuEbhf52kYZ8PdNz9lI'}, 'category': 'confirmation-statement', 'date': '2019-09-23', 'description': 'confirmation-statement-with-updates', 'pages': 4, 'barcode': 'X8EMUH23', 'transaction_id': 'MzI0NDg5NDUxM2FkaXF6a2N4'}, {'type': 'PSC01', 'subcategory': 'notifications', 'action_date': '2019-09-10', 'description_values': {'psc_name': 'Bartosz Pazik', 'notification_date': '2019-09-10'}, 'category': 'persons-with-significant-control', 'links': {'self': '/company/12098424/filing-history/MzI0NDg5MzYzNmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/rAlwZsYfyqfYAV4n_TlFX3c5hqyXmBnKakzKhDL3QL0'}, 'date': '2019-09-23', 'description': 'notification-of-a-person-with-significant-control', 'pages': 2, 'barcode': 'X8EMUDUJ', 'transaction_id': 'MzI0NDg5MzYzNmFkaXF6a2N4'}, {'description_values': {'officer_name': 'Mr Bartosz Pazik', 'appointment_date': '2019-09-10'}, 'category': 'officers', 'links': {'self': '/company/12098424/filing-history/MzI0NDg5MjYxOWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/tK86XekvMQmckMA9Xs8tE9yaBKnCyr0GxrrAcmGUYcU'}, 'date': '2019-09-23', 'description': 'appoint-person-director-company-with-name-date', 'subcategory': 'appointments', 'type': 'AP01', 'action_date': '2019-09-10', 'pages': 2, 'barcode': 'X8EMU9L6', 'transaction_id': 'MzI0NDg5MjYxOWFkaXF6a2N4'}, {'type': 'TM01', 'subcategory': 'termination', 'action_date': '2019-09-10', 'description_values': {'termination_date': '2019-09-10', 'officer_name': 'Lukasz Wojewodzic'}, 'links': {'self': '/company/12098424/filing-history/MzI0NDg5MDc0NGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/RANnOGoDeSbMP2kqvYY-fh2OyyUfGLqmIZfbgl215oE'}, 'category': 'officers', 'date': '2019-09-23', 'description': 'termination-director-company-with-name-termination-date', 'pages': 1, 'barcode': 'X8EMU1SY', 'transaction_id': 'MzI0NDg5MDc0NGFkaXF6a2N4'}, {'description_values': {'cessation_date': '2019-09-09', 'psc_name': 'Ducers Ltd'}, 'category': 'persons-with-significant-control', 'links': {'self': '/company/12098424/filing-history/MzI0NDg5MDU2OWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/HdTB7gx7881GBsfsDkfFTEbWnL5kSpnXrtk7k8Fqgz8'}, 'date': '2019-09-23', 'description': 'cessation-of-a-person-with-significant-control', 'subcategory': 'termination', 'type': 'PSC07', 'action_date': '2019-09-09', 'pages': 1, 'barcode': 'X8EMU1CW', 'transaction_id': 'MzI0NDg5MDU2OWFkaXF6a2N4'}, {'description': 'resolution', 'subcategory': 'certificate', 'type': 'RESOLUTIONS', 'description_values': {'description': 'Resolutions'}, 'date': '2019-09-21', 'links': {'self': '/company/12098424/filing-history/MzI0NDgzOTExNmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/1RFExUTiTyve6UBTLFym0OQqNVSQ2hecc_5EMI0Z7TU'}, 'category': 'resolution', 'associated_filings': [{'category': 'change-of-name', 'date': '2019-09-21', 'description': 'change-of-name-by-resolution', 'type': 'NM01'}], 'resolutions': [{'category': 'change-of-name', 'description': 'resolution-change-of-name', 'description_values': {'resolution_date': '2019-09-20'}, 'subcategory': 'resolution', 'type': 'RES15'}], 'pages': 3, 'barcode': 'X8EF5GMI', 'transaction_id': 'MzI0NDgzOTExNmFkaXF6a2N4'}, {'links': {'self': '/company/12098424/filing-history/MzIzOTA5NTI0M2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/nICiy7Oydb83beqjy1DHvNzoFSFLShsXcDaDnWLt3Cs'}, 'associated_filings': [{'action_date': 1562803200000, 'category': 'capital', 'date': '2019-07-11', 'description': 'statement-of-capital', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '1'}], 'date': '2019-07-11'}, 'type': 'SH01'}, {'category': 'incorporation', 'date': '2019-07-11', 'description': 'model-articles-adopted', 'type': 'MODEL ARTICLES'}], 'date': '2019-07-11', 'category': 'incorporation', 'description': 'incorporation-company', 'type': 'NEWINC', 'pages': 10, 'barcode': 'X89I45EQ', 'transaction_id': 'MzIzOTA5NTI0M2FkaXF6a2N4'}]",25,filing-history-available

该csv是通过Pandas读取,然后我试图扁平化。
x一个一个一个一个x一个一个二个x
尝试扁平化JSON

之前的数据

#attempt at flattening
df2 =  flatten_nested_json_df(df1)
df2.head()

尝试扁平化JSON

后的数据
谢谢你对这件事的任何建议!我已经在这个问题上纠结了很多天,寻找替代方案
谢谢你的建议

deyfvvtc

deyfvvtc1#

您正在使用的函数正在运行,但它需要数据的格式正确。列items中的数据是字符串格式,您需要将其转换回数据结构(列表和字典)。

# https://www.geeksforgeeks.org/python-convert-a-string-representation-of-list-into-list/
from ast import literal_eval
df["items"] = df["items"].apply(literal_eval)

因此,只需正常使用DataFrame中的函数。

flatten_nested_json_df(df)

输出:

相关问题