社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

如何在python中将Json转换为表

Md. Ohidur Rahman • 4 年前 • 2048 次点击  
try:
    # For Python 3.0 and later
    from urllib.request import urlopen
except ImportError:
    # Fall back to Python 2's urllib2
    from urllib2 import urlopen

import certifi
import json

def get_jsonparsed_data(url):
  
    response = urlopen(url, cafile=certifi.where())
    data = response.read().decode("utf-8")
    return json.loads(data)

url = ("https://financialmodelingprep.com/api/v3/ratios/AAPL?apikey=92a1dad5aef4eb31276c19417c31dfeb")
print(get_jsonparsed_data(URL))

Output

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/132710
文章 [ 2 ]  |  最新文章 4 年前
Joran Beasley
Reply   •   1 楼
Joran Beasley    4 年前
import pandas
print(pandas.DataFrame(data))

我想也许你想做的。。。

Michael Hodel
Reply   •   2 楼
Michael Hodel    4 年前
import requests
import pandas as pd

url = (
    "https://financialmodelingprep.com/api/v3/ratios/AAPL?"
    "apikey=92a1dad5aef4eb31276c19417c31dfeb"
)
response = requests.get(url)
data = response.json()
df = pd.DataFrame(data)
df

印刷品:

symbol  date    period  currentRatio    quickRatio  cashRatio   daysOfSalesOutstanding  daysOfInventoryOutstanding  operatingCycle  daysOfPayablesOutstanding   ... priceToSalesRatio   priceEarningsRatio  priceToFreeCashFlowsRatio   priceToOperatingCashFlowsRatio  priceCashFlowRatio  priceEarningsToGrowthRatio  priceSalesRatio dividendYield   enterpriseValueMultiple priceFairValue
0   AAPL    2021-09-25  FY  1.074553    0.909660    0.278449    51.390969   11.276593   62.667561   93.851071   ... 6.786117    26.219656   26.706799   23.861253   23.861253   0.367742    6.786117    0.005828    20.889553   39.348186
1   AAPL    2020-09-26  FY  1.363604    1.218195    0.360710    49.787534   8.741883    58.529418   91.048190   ... 7.272322    34.773150   27.211359   24.746031   24.746031   3.277438    7.272322    0.007053    25.558891   30.553901
2   AAPL    2019-09-28  FY  1.540126    1.384447    0.462022    64.258765   9.263639    73.522404   104.314077  ... 4.420394    20.813515   19.527159   16.573786   16.573786   -62.492578  4.420394    0.012277    14.772472   12.709658
3   AAPL    2018-09-29  FY  1.123843    0.986566    0.221733    67.332499   8.817631    76.150130   124.570214  ... 3.959898    17.666917   16.402259   13.582267   13.582267   0.597709    3.959898    0.013038    13.099961   9.815760
4   AAPL    2017-09-30  FY  1.276063    1.089670    0.201252    56.800671   12.563631   69.364302   126.927606  ... 3.794457    17.989671   17.121402   13.676823   13.676823   1.632758    3.794457    0.014680    12.605749   6.488908