Python yêu cầu json tới khung dữ liệu

Trong bài đăng của mình về trích xuất dữ liệu từ API, Todd đã trình bày một cách hay để xoa bóp JSON vào DataFrame của gấu trúc. Phương pháp này hoạt động hiệu quả khi phản hồi JSON của chúng ta không thay đổi, bởi vì

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
2 chỉ nhận các khóa ở "cấp độ" đầu tiên của từ điển. Tuy nhiên, sẽ phức tạp hơn một chút khi JSON của chúng ta bắt đầu được lồng vào nhau, như tôi đã trải nghiệm khi làm việc với API của Spotify qua thư viện Spotipy. Ví dụ: hãy xem phản hồi từ điểm cuối
{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
3 của họ

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials


spotify_client_id = 'YOUR_ID'
spotify_client_secret  = 'YOUR_SECRET'

client_credentials_manager = SpotifyClientCredentials(
    client_id=spotify_client_id,
    client_secret=spotify_client_secret
)

sp = spotipy.Spotify(
    client_credentials_manager=client_credentials_manager
)
Thiết lập ứng dụng khách Spotipy
track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
Tìm nạp bản nhạc Spotify

Đây là đầu ra

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
Siêu dữ liệu cho một bản nhạc Spotify

Ngoài nhiều thông tin về bản nhạc, Spotify cũng bao gồm thông tin về album chứa bản nhạc đó. Nếu chúng tôi chỉ sử dụng phương pháp

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
2 để biến phản hồi này thành DataFrame, thì chúng tôi sẽ bỏ lỡ tất cả thông tin bổ sung về album đó. Chà, nó sẽ ở đó, chỉ là không dễ tiếp cận

track_response.keys()
Tìm nạp khóa JSON

đầu ra

dict_keys([
    'album',
    'artists',
    'available_markets',
    'disc_number',
    'duration_ms',
    'explicit',
    'external_ids',
    'external_urls',
    'href',
    'id',
    'is_local',
    'name',
    'popularity',
    'preview_url',
    'track_number',
    'type',
    'uri'
])
Đầu ra của
{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
5

Vì vậy, làm thế nào để chúng ta có được xung quanh này?

Chuẩn hóa dữ liệu

Gặp gỡ

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
6

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
0Chuẩn hóa dữ liệu JSON trong Pandas

đầu ra

album. album_typealbum. album nghệ sĩ. có sẵn_marketsalbum. bên ngoài_urls. album spotify. hrefalbum. album ảnh. album hình ảnh. album tên. release_datealbum. release_date_precision. bên ngoài_urls. spotifyhrefidis_localnamepopularitypreview_urltrack_numbertypeuri0album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, BO, BR, CA, CL, CO, CR, EC, GT, HK, HN, I. https. //mở. spotify. com/album/6pWpb4IdPu9vp9m. https. //api. spotify. com/v1/albums/6pWpb4IdPu9v. 6pWpb4IdPu9vp9mOdh5DjY[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Thùng rác tình cảm thực sự2008-03-04day. https. //mở. spotify. com/track/0BDYBajZydY54OT. https. //api. spotify. com/v1/bản nhạc/0BDYBajZydY5. 0BDYBajZydY54OTgQsH940SaiRácRác cảm xúc thật21https. //P. scdn. co/mp3-preview/4fcbcd5a99fc7590. 4trackspotify. theo dõi. 0BDYBajZydY54OTgQsH940

Đúng - thật dễ dàng. gấu trúc lấy đối tượng JSON lồng nhau của chúng tôi, làm phẳng nó và biến nó thành DataFrame

Điều này làm cho cuộc sống của chúng ta dễ dàng hơn khi chúng ta xử lý một bản ghi, nhưng nó thực sự hữu ích khi chúng ta xử lý một phản hồi chứa nhiều bản ghi

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
1Tìm nạp nhiều bản nhạc

đầu ra

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
2Đầu ra
{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
3Chuẩn hóa nhiều bản nhạc

đầu ra

album. album_typealbum. album nghệ sĩ. có sẵn_marketsalbum. bên ngoài_urls. album spotify. hrefalbum. album ảnh. album hình ảnh. album tên. release_datealbum. release_date_precision. bên ngoài_urls. spotifyhrefidis_localnamepopularitypreview_urltrack_numbertypeuri0album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, BO, BR, CA, CL, CO, CR, EC, GT, HK, HN, I. https. //mở. spotify. com/album/6pWpb4IdPu9vp9m. https. //api. spotify. com/v1/albums/6pWpb4IdPu9v. 6pWpb4IdPu9vp9mOdh5DjY[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Rác rưởi cảm xúc thật 3/4/2008 ngày. https. //mở. spotify. com/track/0BDYBajZydY54OT. https. //api. spotify. com/v1/bản nhạc/0BDYBajZydY5. 0BDYBajZydY54OTgQsH940SAIThùng rác cảm xúc thật21https. //P. scdn. co/mp3-preview/4fcbcd5a99fc7590. 4trackspotify. theo dõi. 0BDYBajZydY54OTgQsH9401album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, BO, BR, CA, CL, CO, CR, EC, GT, HK, HN, I. https. //mở. spotify. com/album/6pWpb4IdPu9vp9m. https. //api. spotify. com/v1/albums/6pWpb4IdPu9v. 6pWpb4IdPu9vp9mOdh5DjY[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Rác rưởi cảm xúc thật 3/4/2008 ngày. https. //mở. spotify. com/track/7fdUqrzb8oCcIoK. https. //api. spotify. com/v1/bản nhạc/7fdUqrzb8oCc. 7fdUqrzb8oCcIoKvFuzMrsFALSECCold Son25https. //P. scdn. co/mp3-preview/4cf4e21727def470. 3trackspotify. theo dõi. 7fdUqrzb8oCcIoKvFuzMrs2album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, BO, BR, CA, CL, CO, CR, EC, GT, HK, HN, I. https. //mở. spotify. com/album/6pWpb4IdPu9vp9m. https. //api. spotify. com/v1/albums/6pWpb4IdPu9v. 6pWpb4IdPu9vp9mOdh5DjY[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Rác rưởi cảm xúc thật 3/4/2008 ngày. https. //mở. spotify. com/track/0islTY4Fw6lhYbf. https. //api. spotify. com/v1/bản nhạc/0islTY4Fw6lh. 0islTY4Fw6lhYbfqi8QtdjFALSENhảy lò cò Willie24https. //P. scdn. co/mp3-preview/c7782dc6d7c0bb12. 2trackspotify. theo dõi. 0islTY4Fw6lhYbfqi8Qtdj3album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, BO, BR, CA, CL, CO, CR, EC, GT, HK, HN, I. https. //mở. spotify. com/album/6pWpb4IdPu9vp9m. https. //api. spotify. com/v1/albums/6pWpb4IdPu9v. 6pWpb4IdPu9vp9mOdh5DjY[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Rác rưởi cảm xúc thật 3/4/2008 ngày. https. //mở. spotify. com/track/3jyFLbljUTKjE13. https. //api. spotify. com/v1/bản nhạc/3jyFLbljUTKj. 3jyFLbljUTKjE13nIWXchHFALSEBánh chuồn chuồn26https. //P. scdn. co/mp3-preview/50f419e7d3e8a6a7. 1trackspotify. theo dõi. 3jyFLbljUTKjE13nIWXchH4album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, AU, BO, BR, CA, CL, CO, CR, DO, EC, GT, H. https. //mở. spotify. com/album/5DMvSCwRqfNVlMB. https. //api. spotify. com/v1/albums/5DMvSCwRqfNV. 5DMvSCwRqfNVlMB5LjHOwG[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Sparkle Hard 18/5/2018 ngày. https. //mở. spotify. com/track/6dNmC2YWtWbVOFO. https. //api. spotify. com/v1/bản nhạc/6dNmC2YWtWbV. 6dNmC2YWtWbVOFOdTuRDQsFALSEDKhó khăn - Hãy để chúng ăn nguyên âm35https. //P. scdn. co/mp3-preview/787be9d1bbebcd84. 11trackspotify. theo dõi. 6dNmC2YWtWbVOFOdTuRDQs

Những Con Đường Riêng Biệt (Worlds Apart)

Theo mặc định,

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
6 sử dụng dấu chấm
{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
8 để biểu thị các mức lồng nhau của đối tượng JSON (thực tế được chuyển đổi thành Python
{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
9 bởi Spotipy). Trong trường hợp của chúng tôi, id album được tìm thấy trong
track_response.keys()
0, do đó khoảng thời gian giữa album và id trong DataFrame. Điều này khiến mọi thứ hơi khó chịu nếu chúng tôi muốn lấy Sê-ri từ Khung dữ liệu mới của mình. Trong pandas, chúng ta có thể lấy Sê-ri từ DataFrame theo nhiều cách. Ví dụ, để lấy cột
track_response.keys()
1

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
9

đầu ra

track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
0

hoặc

track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
1

đầu ra

track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
0

Pandas cũng cho phép chúng tôi sử dụng ký hiệu dấu chấm (i. e.

track_response.keys()
2) để lấy một cột dưới dạng Sê-ri, nhưng chỉ khi tên cột của chúng tôi chưa bao gồm dấu chấm. Vì
{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
6 sử dụng dấu chấm làm dấu phân cách theo mặc định, điều này làm hỏng phương thức đó. Mặc dù vậy, đừng lo lắng – việc ghi đè hành vi này cũng đơn giản như ghi đè đối số mặc định trong lệnh gọi hàm

track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
3Ghi đè dấu phân cách

đầu ra

album_album_typealbum_artistsalbum_available_marketsalbum_external_urls_spotifyalbum_hrefalbum_idalbum_imagesalbum_namealbum_release_datealbum_release_date_precision. external_urls_spotifyhrefidis_localnamepopularitypreview_urltrack_numbertypeuri0album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, BO, BR, CA, CL, CO, CR, EC, GT, HK, HN, I. https. //mở. spotify. com/album/6pWpb4IdPu9vp9m. https. //api. spotify. com/v1/albums/6pWpb4IdPu9v. 6pWpb4IdPu9vp9mOdh5DjY[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Rác rưởi cảm xúc thật 3/4/2008 ngày. https. //mở. spotify. com/track/0BDYBajZydY54OT. https. //api. spotify. com/v1/bản nhạc/0BDYBajZydY5. 0BDYBajZydY54OTgQsH940SAIThùng rác cảm xúc thật21https. //P. scdn. co/mp3-preview/4fcbcd5a99fc7590. 4trackspotify. theo dõi. 0BDYBajZydY54OTgQsH9401album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, BO, BR, CA, CL, CO, CR, EC, GT, HK, HN, I. https. //mở. spotify. com/album/6pWpb4IdPu9vp9m. https. //api. spotify. com/v1/albums/6pWpb4IdPu9v. 6pWpb4IdPu9vp9mOdh5DjY[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Rác rưởi cảm xúc thật 3/4/2008 ngày. https. //mở. spotify. com/track/7fdUqrzb8oCcIoK. https. //api. spotify. com/v1/bản nhạc/7fdUqrzb8oCc. 7fdUqrzb8oCcIoKvFuzMrsFALSECCold Son25https. //P. scdn. co/mp3-preview/4cf4e21727def470. 3trackspotify. theo dõi. 7fdUqrzb8oCcIoKvFuzMrs2album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, BO, BR, CA, CL, CO, CR, EC, GT, HK, HN, I. https. //mở. spotify. com/album/6pWpb4IdPu9vp9m. https. //api. spotify. com/v1/albums/6pWpb4IdPu9v. 6pWpb4IdPu9vp9mOdh5DjY[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Rác rưởi cảm xúc thật 3/4/2008 ngày. https. //mở. spotify. com/track/0islTY4Fw6lhYbf. https. //api. spotify. com/v1/bản nhạc/0islTY4Fw6lh. 0islTY4Fw6lhYbfqi8QtdjFALSENhảy lò cò Willie24https. //P. scdn. co/mp3-preview/c7782dc6d7c0bb12. 2trackspotify. theo dõi. 0islTY4Fw6lhYbfqi8Qtdj3album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, BO, BR, CA, CL, CO, CR, EC, GT, HK, HN, I. https. //mở. spotify. com/album/6pWpb4IdPu9vp9m. https. //api. spotify. com/v1/albums/6pWpb4IdPu9v. 6pWpb4IdPu9vp9mOdh5DjY[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Rác rưởi cảm xúc thật 3/4/2008 ngày. https. //mở. spotify. com/track/3jyFLbljUTKjE13. https. //api. spotify. com/v1/bản nhạc/3jyFLbljUTKj. 3jyFLbljUTKjE13nIWXchHFALSEBánh chuồn chuồn26https. //P. scdn. co/mp3-preview/50f419e7d3e8a6a7. 1trackspotify. theo dõi. 3jyFLbljUTKjE13nIWXchH4album[{'external_urls'. {'spotify'. 'https. //mở. s. [AR, AU, BO, BR, CA, CL, CO, CR, DO, EC, GT, H. https. //mở. spotify. com/album/5DMvSCwRqfNVlMB. https. //api. spotify. com/v1/albums/5DMvSCwRqfNV. 5DMvSCwRqfNVlMB5LjHOwG[{'chiều cao'. 640, 'đường dẫn'. 'https. //tôi. scdn. co/ima. Sparkle Hard 18/5/2018 ngày. https. //mở. spotify. com/track/6dNmC2YWtWbVOFO. https. //api. spotify. com/v1/bản nhạc/6dNmC2YWtWbV. 6dNmC2YWtWbVOFOdTuRDQsFALSEDKhó khăn - Hãy để chúng ăn nguyên âm35https. //P. scdn. co/mp3-preview/787be9d1bbebcd84. 11trackspotify. theo dõi. 6dNmC2YWtWbVOFOdTuRDQs

Bây giờ chúng ta có thể quay lại sử dụng ký hiệu dấu chấm để truy cập một cột dưới dạng Chuỗi. Điều này giúp chúng tôi tiết kiệm được một số thao tác gõ mỗi khi chúng tôi muốn lấy một cột và nó trông đẹp hơn một chút (ít nhất là với tôi). tôi nói đáng

track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
4

đầu ra

track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
5

Tôi cần bản ghi đó

Bằng cách bao gồm nhiều tham số hơn khi chúng tôi sử dụng

track_response.keys()
4, chúng tôi thực sự có thể trích xuất dữ liệu mà chúng tôi muốn từ phản hồi API của mình

Từ các phản hồi của chúng tôi ở trên, chúng tôi có thể thấy rằng thuộc tính

track_response.keys()
5 chứa danh sách các nghệ sĩ được liên kết với một bản nhạc

track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
6

đầu ra

track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
7

Giả sử tôi muốn tải dữ liệu này vào cơ sở dữ liệu sau. Sẽ thật tuyệt nếu có một bảng tham gia ánh xạ từng nghệ sĩ được liên kết với từng bản nhạc. May mắn thay, điều này có thể thực hiện được với các tham số

track_response.keys()
7 và
track_response.keys()
8 của
{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
6

track_response.keys()
7 cho
{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
6 biết đường dẫn của các khóa dẫn đến từng bản ghi riêng lẻ trong đối tượng JSON. Trong trường hợp của chúng tôi, chúng tôi muốn lấy mọi id nghệ sĩ, vì vậy lệnh gọi hàm của chúng tôi sẽ giống như

track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
8

bên ngoài_urlshrefidnametypeuri1{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/7. https. //api. spotify. com/v1/nghệ sĩ/7wyRA7deGRx. 7wyRA7deGRxozTyBc6QXPeStephen Malkmus & The Jicksartistsspotify. nghệ sĩ. 7wyRA7deGRxozTyBc6QXPe1{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/0. https. //api. spotify. com/v1/nghệ sĩ/0WISkx0PwT6. 0WISkx0PwT6lYWdPqKUJY8Stephen Malkmusartistspotify. nghệ sĩ. 0WISkx0PwT6lYWdPqKUJY82{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/7. https. //api. spotify. com/v1/nghệ sĩ/7uStwCeP54Z. 7uStwCeP54Za8gXUFCf5L7The Jicksartistsspotify. nghệ sĩ. 7uStwCeP54Za8gXUFCf5L73{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/7. https. //api. spotify. com/v1/nghệ sĩ/7wyRA7deGRx. 7wyRA7deGRxozTyBc6QXPeStephen Malkmus & The Jicksartistsspotify. nghệ sĩ. 7wyRA7deGRxozTyBc6QXPe4{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/0. https. //api. spotify. com/v1/nghệ sĩ/0WISkx0PwT6. 0WISkx0PwT6lYWdPqKUJY8Stephen Malkmusartistspotify. nghệ sĩ. 0WISkx0PwT6lYWdPqKUJY85{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/7. https. //api. spotify. com/v1/nghệ sĩ/7uStwCeP54Z. 7uStwCeP54Za8gXUFCf5L7The Jicksartistsspotify. nghệ sĩ. 7uStwCeP54Za8gXUFCf5L76{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/7. https. //api. spotify. com/v1/nghệ sĩ/7wyRA7deGRx. 7wyRA7deGRxozTyBc6QXPeStephen Malkmus & The Jicksartistsspotify. nghệ sĩ. 7wyRA7deGRxozTyBc6QXPe7{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/0. https. //api. spotify. com/v1/nghệ sĩ/0WISkx0PwT6. 0WISkx0PwT6lYWdPqKUJY8Stephen Malkmusartistspotify. nghệ sĩ. 0WISkx0PwT6lYWdPqKUJY88{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/7. https. //api. spotify. com/v1/nghệ sĩ/7uStwCeP54Z. 7uStwCeP54Za8gXUFCf5L7The Jicksartistsspotify. nghệ sĩ. 7uStwCeP54Za8gXUFCf5L79{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/7. https. //api. spotify. com/v1/nghệ sĩ/7wyRA7deGRx. 7wyRA7deGRxozTyBc6QXPeStephen Malkmus & The Jicksartistsspotify. nghệ sĩ. 7wyRA7deGRxozTyBc6QXPe10{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/0. https. //api. spotify. com/v1/nghệ sĩ/0WISkx0PwT6. 0WISkx0PwT6lYWdPqKUJY8Stephen Malkmusartistspotify. nghệ sĩ. 0WISkx0PwT6lYWdPqKUJY811{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/7. https. //api. spotify. com/v1/nghệ sĩ/7uStwCeP54Z. 7uStwCeP54Za8gXUFCf5L7The Jicksartistsspotify. nghệ sĩ. 7uStwCeP54Za8gXUFCf5L712{'spotify'. 'https. //mở. spotify. com/nghệ sĩ/7. https. //api. spotify. com/v1/nghệ sĩ/7wyRA7deGRx. 7wyRA7deGRxozTyBc6QXPeStephen Malkmus & The Jicksartistsspotify. nghệ sĩ. 7wyRA7deGRxozTyBc6QXPe

Thật tuyệt – chúng ta gần đến nơi rồi. Bây giờ chúng tôi muốn sử dụng tham số

track_response.keys()
8 để chỉ định dữ liệu nào chúng tôi muốn đưa vào từ phần còn lại của đối tượng JSON. Trong trường hợp của chúng tôi, chúng tôi muốn giữ id bản nhạc và ánh xạ nó tới id nghệ sĩ. Nếu chúng tôi nhìn lại phản hồi API của mình, tên của cột bao gồm bản nhạc được gọi, một cách thích hợp,
dict_keys([
    'album',
    'artists',
    'available_markets',
    'disc_number',
    'duration_ms',
    'explicit',
    'external_ids',
    'external_urls',
    'href',
    'id',
    'is_local',
    'name',
    'popularity',
    'preview_url',
    'track_number',
    'type',
    'uri'
])
2, vì vậy lệnh gọi chức năng đầy đủ của chúng tôi sẽ giống như thế này

track_response = sp.track('0BDYBajZydY54OTgQsH940')
print(track_response)
9

đầu ra

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
0

Uh oh - một lỗi. Chuyện gì đang xảy ra vậy? . gấu trúc không thích điều đó và nó cho chúng tôi một lỗi hữu ích để cho chúng tôi biết như vậy.

dict_keys([
    'album',
    'artists',
    'available_markets',
    'disc_number',
    'duration_ms',
    'explicit',
    'external_ids',
    'external_urls',
    'href',
    'id',
    'is_local',
    'name',
    'popularity',
    'preview_url',
    'track_number',
    'type',
    'uri'
])
4

Có hai tham số nữa chúng ta có thể sử dụng để khắc phục lỗi này.

dict_keys([
    'album',
    'artists',
    'available_markets',
    'disc_number',
    'duration_ms',
    'explicit',
    'external_ids',
    'external_urls',
    'href',
    'id',
    'is_local',
    'name',
    'popularity',
    'preview_url',
    'track_number',
    'type',
    'uri'
])
5 và
dict_keys([
    'album',
    'artists',
    'available_markets',
    'disc_number',
    'duration_ms',
    'explicit',
    'external_ids',
    'external_urls',
    'href',
    'id',
    'is_local',
    'name',
    'popularity',
    'preview_url',
    'track_number',
    'type',
    'uri'
])
6. Đây là những chuỗi chúng tôi sẽ thêm vào phần đầu của bản ghi và siêu dữ liệu của mình để ngăn những xung đột đặt tên này. Vì chúng tôi đang xử lý id nghệ sĩ Spotify cho hồ sơ của chúng tôi và id bản nhạc Spotify làm siêu dữ liệu, tôi sẽ sử dụng
dict_keys([
    'album',
    'artists',
    'available_markets',
    'disc_number',
    'duration_ms',
    'explicit',
    'external_ids',
    'external_urls',
    'href',
    'id',
    'is_local',
    'name',
    'popularity',
    'preview_url',
    'track_number',
    'type',
    'uri'
])
7 và
dict_keys([
    'album',
    'artists',
    'available_markets',
    'disc_number',
    'duration_ms',
    'explicit',
    'external_ids',
    'external_urls',
    'href',
    'id',
    'is_local',
    'name',
    'popularity',
    'preview_url',
    'track_number',
    'type',
    'uri'
])
8 tương ứng. Khi đã xong, tôi sẽ chỉ chọn những cột mà chúng ta quan tâm

{
  "album": {
    "album_type": "album",
    "artists": [{
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
        },
        "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
        "id": "7wyRA7deGRxozTyBc6QXPe",
        "name": "Stephen Malkmus & The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
        },
        "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
        "id": "0WISkx0PwT6lYWdPqKUJY8",
        "name": "Stephen Malkmus",
        "type": "artist",
        "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
      },
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
        },
        "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
        "id": "7uStwCeP54Za8gXUFCf5L7",
        "name": "The Jicks",
        "type": "artist",
        "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
      }
    ],
    "available_markets": ["AR",
      "BO",
      "BR",
      "CA",
      "...",
      "US",
      "UY",
      "VN"
    ],
    "external_urls": {
      "spotify": "https://open.spotify.com/album/6pWpb4IdPu9vp9mOdh5DjY"
    },
    "href": "https://api.spotify.com/v1/albums/6pWpb4IdPu9vp9mOdh5DjY",
    "id": "6pWpb4IdPu9vp9mOdh5DjY",
    "images": [{
        "height": 640,
        "url": "https://i.scdn.co/image/918fdb6fdffccf2bd2dd1a1a93136000f8cf9bd3",
        "width": 640
      },
      {
        "height": 300,
        "url": "https://i.scdn.co/image/fb39290ebca6fac424d4a40611a7e0d1146c5f88",
        "width": 300
      },
      {
        "height": 64,
        "url": "https://i.scdn.co/image/873da4a0a21acd96e4a0036c9ecd0580b62652d4",
        "width": 64
      }
    ],
    "name": "Real Emotional Trash",
    "release_date": "2008-03-04",
    "release_date_precision": "day",
    "type": "album",
    "uri": "spotify:album:6pWpb4IdPu9vp9mOdh5DjY"
  },
  "artists": [{
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7wyRA7deGRxozTyBc6QXPe"
      },
      "href": "https://api.spotify.com/v1/artists/7wyRA7deGRxozTyBc6QXPe",
      "id": "7wyRA7deGRxozTyBc6QXPe",
      "name": "Stephen Malkmus & The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7wyRA7deGRxozTyBc6QXPe"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/0WISkx0PwT6lYWdPqKUJY8"
      },
      "href": "https://api.spotify.com/v1/artists/0WISkx0PwT6lYWdPqKUJY8",
      "id": "0WISkx0PwT6lYWdPqKUJY8",
      "name": "Stephen Malkmus",
      "type": "artist",
      "uri": "spotify:artist:0WISkx0PwT6lYWdPqKUJY8"
    },
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/7uStwCeP54Za8gXUFCf5L7"
      },
      "href": "https://api.spotify.com/v1/artists/7uStwCeP54Za8gXUFCf5L7",
      "id": "7uStwCeP54Za8gXUFCf5L7",
      "name": "The Jicks",
      "type": "artist",
      "uri": "spotify:artist:7uStwCeP54Za8gXUFCf5L7"
    }
  ],
  "available_markets": ["AR",
    "BO",
    "BR",
    "CA",
    "...",
    "US",
    "UY",
    "VN"
  ],
  "disc_number": 1,
  "duration_ms": 608826,
  "explicit": False,
  "external_ids": {
    "isrc": "USMTD0877204"
  },
  "external_urls": {
    "spotify": "https://open.spotify.com/track/0BDYBajZydY54OTgQsH940"
  },
  "href": "https://api.spotify.com/v1/tracks/0BDYBajZydY54OTgQsH940",
  "id": "0BDYBajZydY54OTgQsH940",
  "is_local": False,
  "name": "Real Emotional Trash",
  "popularity": 21,
  "preview_url": "https://p.scdn.co/mp3-preview/4fcbcd5a99fc7590d5819849e1aad3eff981dc75?cid=be22fd00039241bc96d161a63876b54c",
  "track_number": 4,
  "type": "track",
  "uri": "spotify:track:0BDYBajZydY54OTgQsH940"
}
1

đầu ra

sp_track_idsp_artist_id00BDYBajZydY54OTgQsH9407wyRA7deGRxozTyBc6QXPe10BDYBajZydY54OTgQsH9400WISkx0PwT6lYWdPqKUJY820BDYBajZydY54OTgQsH9407uStwCeP54Za8gXUFCf5L737fdUqrzb8oCcIoKvFuzMrs7wyRA7deGRxozTyBc6QXPe47fdUqrzb8oCcIoKvFuzMrs0WISkx0PwT6lYWdPqKUJY857fdUqrzb8oCcIoKvFuzMrs7uStwCeP54Za8gXUFCf5L760islTY4Fw6lhYbfqi8Qtdj7wyRA7deGRxozTyBc6QXPe70islTY4Fw6lhYbfqi8Qtdj0WISkx0PwT6lYWdPqKUJY880islTY4Fw6lhYbfqi8Qtdj7uStwCeP54Za8gXUFCf5L793jyFLbljUTKjE13nIWXchH7wyRA7deGRxozTyBc6QXPe103jyFLbljUTKjE13nIWXchH0WISkx0PwT6lYWdPqKUJY8113jyFLbljUTKjE13nIWXchH7uStwCeP54Za8gXUFCf5L7126dNmC2YWtWbVOFOdTuRDQs7wyRA7deGRxozTyBc6QXPe

Làm cách nào để chuyển đổi yêu cầu JSON thành DataFrame trong Python?

Hàm json_normalize() dùng để chuyển đổi chuỗi JSON thành DataFrame . Bạn có thể tải chuỗi JSON bằng json. chức năng tải (). Truyền đối tượng JSON tới json_normalize() , trả về Khung dữ liệu Pandas.

Làm cách nào để chuyển đổi phản hồi API thành DataFrame trong Python?

Dịch dữ liệu có cấu trúc JSON từ API sang Khung dữ liệu Pandas là một trong những kỹ năng đầu tiên bạn cần để mở rộng bộ kỹ năng Jupyter/Pandas non trẻ của mình. .
Bước 1. nhập gấu trúc. .
Bước 2. Yêu cầu nhập khẩu. .
Bước 3. Thực hiện Yêu cầu GET từ Điểm cuối API. .
Bước 4. Trích xuất dữ liệu từ Yêu cầu bằng Phương thức Json()

Làm cách nào để phân tích dữ liệu JSON trong gấu trúc?

Phân tích cú pháp tập dữ liệu JSON bằng Pandas .
{ "col1". { "hàng1". 1, "hàng2". 2, "hàng3". 3 } "col2". { "hàng1". "x", "hàng2". "y", "hàng3". "z" } }
nhập gấu trúc dưới dạng pd df= pd. DataFrame([['a','b'],['c','d']], index = ['row1','row2'], column = ['col1','col2'])
df. to_json(orient='index')
df. to_json(orient='split')

Gấu trúc có thể nhập JSON không?

Bạn có thể làm điều này cho URL, tệp, tệp nén và bất kỳ thứ gì ở định dạng json. Trong bài đăng này, bạn sẽ học cách làm điều đó với Python. Đầu tiên tải dữ liệu json bằng phương thức read_json của Pandas, sau đó dữ liệu được tải vào Khung dữ liệu của Pandas .