如何将 json 文件转换为 pandas 可读

How to convert json file as pandas readable

我有一个实时股票 API 用于 ML 实施 我使用 Google colab 作为环境 我已经与 API 建立联系,状态为成功,我收到了一个 json 文本文件,我已将其解析为 .json() 并使其可见并缩进。

{
   "Meta Data": {
    "1. Information": "Daily Prices and Volumes for Digital Currency",
    "2. Digital Currency Code": "BTC",
    "3. Digital Currency Name": "Bitcoin",
    "4. Market Code": "CNY",
    "5. Market Name": "Chinese Yuan",
    "6. Last Refreshed": "2021-01-22 00:00:00",
    "7. Time Zone": "UTC"
},
"Time Series (Digital Currency Daily)": {
    "2021-01-22": {
        "1a. open (CNY)": "199365.55938000",
        "1b. open (USD)": "30851.99000000",
        "2a. high (CNY)": "199443.03876000",
        "2b. high (USD)": "30863.98000000",
        "3a. low (CNY)": "188839.21986000",
        "3b. low (USD)": "29223.03000000",
        "4a. close (CNY)": "192933.34920000",
        "4b. close (USD)": "29856.60000000",
        "5. volume": "12132.72474600",
        "6. market cap (USD)": "12132.72474600"
    },
    "2021-01-21": {
        "1a. open (CNY)": "229195.70226000",
        "1b. open (USD)": "35468.23000000",
        "2a. high (CNY)": "230047.20000000",
        "2b. high (USD)": "35600.00000000",
        "3a. low (CNY)": "194318.80200000",
        "3b. low (USD)": "30071.00000000",
        "4a. close (CNY)": "199353.54006000",
        "4b. close (USD)": "30850.13000000",
        "5. volume": "131803.18292600",
        "6. market cap (USD)": "131803.18292600" 

现在的问题是我们如何使这个 json 文件变得 pandas 可读。欢迎提出任何建议

读入时间序列,然后 transpose(), T。然后重命名您的列。

df = pd.DataFrame(d["Time Series (Digital Currency Daily)"]).T
df.columns = ['open CNY', 'open USD', 'high CNY', 'high USD',
   'low CNY', 'low USD', 'close CNY', 'close USD',
   'volume', 'market cap USD']

输出

                open CNY  open USD      high CNY  high USD       low CNY   low USD     close CNY close USD         volume market cap USD
2021-01-22  199365.55938  30851.99  199443.03876  30863.98  188839.21986  29223.03  192933.34920  29856.60   12132.724746   12132.724746
2021-01-21  229195.70226  35468.23  230047.20000  35600.00  194318.80200  30071.00  199353.54006  30850.13  131803.182926  131803.182926