Я пытаюсь преобразовать JSON-файл в CSV-файл.Поскольку мой json-файл представляет собой список словарей, я хотел бы преобразовать его в pandas dataframe, а затем преобразовать в csv.Я хочу выбрать определенные словари, например, спонсор, участник, год и т. Д.
Я не знаю, как собрать определенные индексы и добавить их в список, а затем преобразовать в фрейм данных.
import requests, json
import pandas as pd
query = {"legal_name": "Apple Inc", "year":"2010"}
results = requests.post('https://www.lobbyview.org/public/api/reports', data = json.dumps(query))
flag = True
length_r = len(result)
channels_list = []
print(length)
while flag:
for i in range(0,length):
if result[i] == "specific_issues":
length_s = len(specific_issues)
for j in range(0,length_s):
if specific_issues[j] == "bills_by_algo":
length_b = len(bills_by_algo)
for k in range(0,length_b):
if bilss_by_algo[k] == "sponsor":
channels_list.append(sponsor['party'],sponsor['lastname'])
flag = False
dataset = pd.DataFrame(channels_list)
dataset.sample(2)
«Это то, что я пытался».«Ниже мой файл JSON.»
{
"result": [
{
"issue_codes": [
"BUD",
"EDU"
],
"received": 1436367560,
"has_amendments": false,
"client_name": "Apple Inc",
"period": "2nd Quarter (Apr 1 - June 30)",
"registrant": "Bernstein Strategy Group",
"amount": 20000,
"client": {
"legal_name": "Apple Inc",
"name": "Apple, Inc.",
"naics": "334111",
"gvkey": "1690",
"ticker": "AAPL",
"id": null,
"bvdid": "US942404110"
},
"specific_issues": [
{
"text": "HR 5 -- Student Success Act -- blended learning provision S. 1177 Every Child Achieves Act -- specifically seeking addition of educational technology program and amendments related to student privacy and homework gap Unintroduced House legislation to update the Federal Education Records Privacy Act HR 2092 -- Student Digital Privacy and Parental Rights Act of 2015 S. 1341 -- Student Privacy Protection Act S. 1322 -- Protecting Student Privacy Act Unintroduced House and Senate legislation to address the homework gap Unintroduced Senate student privacy legislation \n",
"bills_by_algo": [
{
"titles": [
"Student Digital Privacy and Parental Rights Act of 2015",
"To require operators that provide online and similar services to educational agencies or institutions to protect the privacy and security of personally identifiable information, and for other purposes.",
"Student Digital Privacy and Parental Rights Act of 2015"
],
"top_terms": [
"Education",
"Child safety and welfare"
],
"number": 2092,
"session": 114,
"public_law": "",
"sponsor": {
"firstname": "Luke",
"district": 6,
"title": "rep",
"lastname": "Messer",
"religion": null,
"state": "IN",
"gender": "M",
"party": "Republican",
"id": 412540
},
"committees": [
"House Education and the Workforce",
"House Energy and Commerce"
],
"introduced": 1430280000,
"type": "HR",
"id": "114_HR2092"
},
{
"titles": [
"Student Success Act",
"To support State and local accountability for public education, protect State and local authority, inform parents of the performance of their children's schools, and for other purposes.",
"Schools of the Future Act",
"Student Success Act",
"Student Success Act"
],
"top_terms": [
"Education",
"Abortion"
],
"number": 5,
"session": 114,
"public_law": "",
"sponsor": {
"firstname": "John",
"district": 2,
"title": "rep",
"lastname": "Kline",
"religion": null,
"state": "MN",
"gender": "M",
"party": "Republican",
"id": 400224
},
"committees": [
"House Education and the Workforce",
"House Financial Services"
],
"introduced": 1422939600,
"type": "HR",
"id": "114_HR5"
},