IIUC:
pd.concat(
pd.DataFrame([requests.get( http://books.com/?x}).json() for x in books]),
ignore_index=True)
或者,您可以将 JSON 响应收集到列表中并执行以下操作:
In [30]: pd.concat([pd.DataFrame(x['bookInfo']) for x in d], ignore_index=True)
Out[30]:
book_created book_rating book_sold
0 2017-05-31 3 0
1 2017-05-31 2 1
2 2017-05-31 3 0
3 2017-05-31 2 1
4 2017-05-31 3 0
5 2017-05-31 2 1
or
In [25]: pd.DataFrame([y for x in d for y in x['bookInfo']])
Out[25]:
book_created book_rating book_sold
0 2017-05-31 3 0
1 2017-05-31 2 1
2 2017-05-31 3 0
3 2017-05-31 2 1
4 2017-05-31 3 0
5 2017-05-31 2 1
where d
是您发布的字典列表:
In [20]: d
Out[20]:
[{'bookInfo': [{'book_created': '2017-05-31',
'book_rating': 3,
'book_sold': 0},
{'book_created': '2017-05-31', 'book_rating': 2, 'book_sold': 1}],
'book_reading_speed': '4.29',
'book_sale_date': '2017-05-31'},
{'bookInfo': [{'book_created': '2017-05-31',
'book_rating': 3,
'book_sold': 0},
{'book_created': '2017-05-31', 'book_rating': 2, 'book_sold': 1}],
'book_reading_speed': '4.29',
'book_sale_date': '2017-05-31'},
{'bookInfo': [{'book_created': '2017-05-31',
'book_rating': 3,
'book_sold': 0},
{'book_created': '2017-05-31', 'book_rating': 2, 'book_sold': 1}],
'book_reading_speed': '4.29',
'book_sale_date': '2017-05-31'}]