pd.concat是将这两个数据帧组合成一个循环的正确函数吗?

问题描述 投票:0回答:1

我正在尝试通过Spotipy库访问Spotify的API。我正在使用循环为我听过的最后50首歌曲的曲目和音频功能建立数据帧。

我想可能有更有效的方法,但是到目前为止,我有一个循环,可以将数据添加到名为pddf的现有数据帧中。

我希望通过逐行添加列来完成此操作,因为添加的数据将取决于该行中的轨道uri。

for index, row in pddf.iterrows():
    track = list(row['track.uri'])
    track = re.findall('(?<=track:).*$', row['track.uri'])
    features = sp.audio_features(tracks=track)
    audio_features = pd.DataFrame(features)
    now = datetime.datetime.now()
    date = '%d/%d/%d' % (now.month, now.day, now.year)
    audio_features['Date'] = date
    audio_features = audio_features[
        ['Date', 'acousticness', 'analysis_url', 'danceability', 'duration_ms', 'energy', 'id',
         'instrumentalness', 'key', 'liveness', 'loudness', 'mode', 'speechiness', 'tempo', 'time_signature',
         'track_href', 'type', 'uri', 'valence']]
    pddf = pd.concat([pddf, audio_features], axis=0)

我感觉是pd.concat是问题,还是我处理问题的效率低下,但它返回此信息:

0   2020-03-19T02:31:16.952Z    https://open.spotify.com/album/7z4GhRfLqfSkqrj5F3Yt2B   https://api.spotify.com/v1/albums/7z4GhRfLqfSkqrj5F3Yt2B    album   spotify:album:7z4GhRfLqfSkqrj5F3Yt2B    album   [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Gso3d4CscCijv0lmajZWs'}, 'href': 'https://api.spotify.com/v1/artists/4Gso3d4CscCijv0lmajZWs', 'id': '4Gso3d4CscCijv0lmajZWs', 'name': 'Don Toliver', 'type': 'artist', 'uri': 'spotify:artist:4Gso3d4CscCijv0lmajZWs'}]    ['AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'ID', 'IE', 'IL', 'IS', 'IT', 'JO', 'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'OM', 'PA', 'PE', 'PH', 'PL', 'PS', 'PT', 'PY', 'QA', 'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN', 'TR', 'TW', 'US', 'UY', 'VN', 'ZA']    https://open.spotify.com/album/7z4GhRfLqfSkqrj5F3Yt2B   https://api.spotify.com/v1/albums/7z4GhRfLqfSkqrj5F3Yt2B    7z4GhRfLqfSkqrj5F3Yt2B  [{'height': 640, 'url': 'https://i.scdn.co/image/ab67616d0000b273da7dc7bd8beaa9bc9ceb8297', 'width': 640}, {'height': 300, 'url': 'https://i.scdn.co/image/ab67616d00001e02da7dc7bd8beaa9bc9ceb8297', 'width': 300}, {'height': 64, 'url': 'https://i.scdn.co/image/ab67616d00004851da7dc7bd8beaa9bc9ceb8297', 'width': 64}]    Heaven Or Hell  3/13/20 day 12  album   spotify:album:7z4GhRfLqfSkqrj5F3Yt2B    [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Gso3d4CscCijv0lmajZWs'}, 'href': 'https://api.spotify.com/v1/artists/4Gso3d4CscCijv0lmajZWs', 'id': '4Gso3d4CscCijv0lmajZWs', 'name': 'Don Toliver', 'type': 'artist', 'uri': 'spotify:artist:4Gso3d4CscCijv0lmajZWs'}]    ['AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'ID', 'IE', 'IL', 'IS', 'IT', 'JO', 'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'OM', 'PA', 'PE', 'PH', 'PL', 'PS', 'PT', 'PY', 'QA', 'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN', 'TR', 'TW', 'US', 'UY', 'VN', 'ZA']    1   180674  FALSE   USAT21904066    https://open.spotify.com/track/47IXLhp3c6mu7NqvpuhuLi   https://api.spotify.com/v1/tracks/47IXLhp3c6mu7NqvpuhuLi    47IXLhp3c6mu7NqvpuhuLi  FALSE   Can't Feel My Legs  67  https://p.scdn.co/mp3-preview/64421f93c1a50553650656789726942083f5c567?cid=a98a5116ec7149be9fbec4e5ff8afc18 6   track   spotify:track:47IXLhp3c6mu7NqvpuhuLi                                                                            
1   2020-03-19T02:28:17.087Z    https://open.spotify.com/album/7z4GhRfLqfSkqrj5F3Yt2B   https://api.spotify.com/v1/albums/7z4GhRfLqfSkqrj5F3Yt2B    album   spotify:album:7z4GhRfLqfSkqrj5F3Yt2B    album   [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Gso3d4CscCijv0lmajZWs'}, 'href': 'https://api.spotify.com/v1/artists/4Gso3d4CscCijv0lmajZWs', 'id': '4Gso3d4CscCijv0lmajZWs', 'name': 'Don Toliver', 'type': 'artist', 'uri': 'spotify:artist:4Gso3d4CscCijv0lmajZWs'}]    ['AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'ID', 'IE', 'IL', 'IS', 'IT', 'JO', 'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'OM', 'PA', 'PE', 'PH', 'PL', 'PS', 'PT', 'PY', 'QA', 'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN', 'TR', 'TW', 'US', 'UY', 'VN', 'ZA']    https://open.spotify.com/album/7z4GhRfLqfSkqrj5F3Yt2B   https://api.spotify.com/v1/albums/7z4GhRfLqfSkqrj5F3Yt2B    7z4GhRfLqfSkqrj5F3Yt2B  [{'height': 640, 'url': 'https://i.scdn.co/image/ab67616d0000b273da7dc7bd8beaa9bc9ceb8297', 'width': 640}, {'height': 300, 'url': 'https://i.scdn.co/image/ab67616d00001e02da7dc7bd8beaa9bc9ceb8297', 'width': 300}, {'height': 64, 'url': 'https://i.scdn.co/image/ab67616d00004851da7dc7bd8beaa9bc9ceb8297', 'width': 64}]    Heaven Or Hell  3/13/20 day 12  album   spotify:album:7z4GhRfLqfSkqrj5F3Yt2B    [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Gso3d4CscCijv0lmajZWs'}, 'href': 'https://api.spotify.com/v1/artists/4Gso3d4CscCijv0lmajZWs', 'id': '4Gso3d4CscCijv0lmajZWs', 'name': 'Don Toliver', 'type': 'artist', 'uri': 'spotify:artist:4Gso3d4CscCijv0lmajZWs'}]    ['AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'ID', 'IE', 'IL', 'IS', 'IT', 'JO', 'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'OM', 'PA', 'PE', 'PH', 'PL', 'PS', 'PT', 'PY', 'QA', 'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN', 'TR', 'TW', 'US', 'UY', 'VN', 'ZA']    1   171210  TRUE    USAT22001224    https://open.spotify.com/track/79EVtighsMYkWahVb9MnF8   https://api.spotify.com/v1/tracks/79EVtighsMYkWahVb9MnF8    79EVtighsMYkWahVb9MnF8  FALSE   Wasted  68  https://p.scdn.co/mp3-preview/2d75b6c8a2699b911fbcaff1d2625bb6df4d183b?cid=a98a5116ec7149be9fbec4e5ff8afc18 5   track   spotify:track:79EVtighsMYkWahVb9MnF8                                                                            
2   2020-03-19T02:25:25.899Z    https://open.spotify.com/album/7z4GhRfLqfSkqrj5F3Yt2B   https://api.spotify.com/v1/albums/7z4GhRfLqfSkqrj5F3Yt2B    album   spotify:album:7z4GhRfLqfSkqrj5F3Yt2B    album   [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Gso3d4CscCijv0lmajZWs'}, 'href': 'https://api.spotify.com/v1/artists/4Gso3d4CscCijv0lmajZWs', 'id': '4Gso3d4CscCijv0lmajZWs', 'name': 'Don Toliver', 'type': 'artist', 'uri': 'spotify:artist:4Gso3d4CscCijv0lmajZWs'}]    ['AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'ID', 'IE', 'IL', 'IS', 'IT', 'JO', 'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'OM', 'PA', 'PE', 'PH', 'PL', 'PS', 'PT', 'PY', 'QA', 'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN', 'TR', 'TW', 'US', 'UY', 'VN', 'ZA']    https://open.spotify.com/album/7z4GhRfLqfSkqrj5F3Yt2B   https://api.spotify.com/v1/albums/7z4GhRfLqfSkqrj5F3Yt2B    7z4GhRfLqfSkqrj5F3Yt2B  [{'height': 640, 'url': 'https://i.scdn.co/image/ab67616d0000b273da7dc7bd8beaa9bc9ceb8297', 'width': 640}, {'height': 300, 'url': 'https://i.scdn.co/image/ab67616d00001e02da7dc7bd8beaa9bc9ceb8297', 'width': 300}, {'height': 64, 'url': 'https://i.scdn.co/image/ab67616d00004851da7dc7bd8beaa9bc9ceb8297', 'width': 64}]    Heaven Or Hell  3/13/20 day 12  album   spotify:album:7z4GhRfLqfSkqrj5F3Yt2B    [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Gso3d4CscCijv0lmajZWs'}, 'href': 'https://api.spotify.com/v1/artists/4Gso3d4CscCijv0lmajZWs', 'id': '4Gso3d4CscCijv0lmajZWs', 'name': 'Don Toliver', 'type': 'artist', 'uri': 'spotify:artist:4Gso3d4CscCijv0lmajZWs'}]    ['AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'ID', 'IE', 'IL', 'IS', 'IT', 'JO', 'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'OM', 'PA', 'PE', 'PH', 'PL', 'PS', 'PT', 'PY', 'QA', 'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN', 'TR', 'TW', 'US', 'UY', 'VN', 'ZA']    1   167915  TRUE    USAT22001223    https://open.spotify.com/track/527k23H0A4Q0UJN3vGs0Da   https://api.spotify.com/v1/tracks/527k23H0A4Q0UJN3vGs0Da    527k23H0A4Q0UJN3vGs0Da  FALSE   After Party 71  https://p.scdn.co/mp3-preview/647283c4f566948abd74087459fe592b5fd39dac?cid=a98a5116ec7149be9fbec4e5ff8afc18 4   track   spotify:track:527k23H0A4Q0UJN3vGs0Da                                                                            
3   2020-03-19T02:18:06.030Z    https://open.spotify.com/album/7z4GhRfLqfSkqrj5F3Yt2B   https://api.spotify.com/v1/albums/7z4GhRfLqfSkqrj5F3Yt2B    album   spotify:album:7z4GhRfLqfSkqrj5F3Yt2B    album   [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Gso3d4CscCijv0lmajZWs'}, 'href': 'https://api.spotify.com/v1/artists/4Gso3d4CscCijv0lmajZWs', 'id': '4Gso3d4CscCijv0lmajZWs', 'name': 'Don Toliver', 'type': 'artist', 'uri': 'spotify:artist:4Gso3d4CscCijv0lmajZWs'}]    ['AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'ID', 'IE', 'IL', 'IS', 'IT', 'JO', 'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'OM', 'PA', 'PE', 'PH', 'PL', 'PS', 'PT', 'PY', 'QA', 'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN', 'TR', 'TW', 'US', 'UY', 'VN', 'ZA']    https://open.spotify.com/album/7z4GhRfLqfSkqrj5F3Yt2B   https://api.spotify.com/v1/albums/7z4GhRfLqfSkqrj5F3Yt2B    7z4GhRfLqfSkqrj5F3Yt2B  [{'height': 640, 'url': 'https://i.scdn.co/image/ab67616d0000b273da7dc7bd8beaa9bc9ceb8297', 'width': 640}, {'height': 300, 'url': 'https://i.scdn.co/image/ab67616d00001e02da7dc7bd8beaa9bc9ceb8297', 'width': 300}, {'height': 64, 'url': 'https://i.scdn.co/image/ab67616d00004851da7dc7bd8beaa9bc9ceb8297', 'width': 64}]    Heaven Or Hell  3/13/20 day 12  album   spotify:album:7z4GhRfLqfSkqrj5F3Yt2B    [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Gso3d4CscCijv0lmajZWs'}, 'href': 'https://api.spotify.com/v1/artists/4Gso3d4CscCijv0lmajZWs', 'id': '4Gso3d4CscCijv0lmajZWs', 'name': 'Don Toliver', 'type': 'artist', 'uri': 'spotify:artist:4Gso3d4CscCijv0lmajZWs'}, {'external_urls': {'spotify': 'https://open.spotify.com/artist/3xWSt0mL474uQlh5Zm6NsW'}, 'href': 'https://api.spotify.com/v1/artists/3xWSt0mL474uQlh5Zm6NsW', 'id': '3xWSt0mL474uQlh5Zm6NsW', 'name': 'Offset', 'type': 'artist', 'uri': 'spotify:artist:3xWSt0mL474uQlh5Zm6NsW'}, {'external_urls': {'spotify': 'https://open.spotify.com/artist/0VRj0yCOv2FXJNP47XQnx5'}, 'href': 'https://api.spotify.com/v1/artists/0VRj0yCOv2FXJNP47XQnx5', 'id': '0VRj0yCOv2FXJNP47XQnx5', 'name': 'Quavo', 'type': 'artist', 'uri': 'spotify:artist:0VRj0yCOv2FXJNP47XQnx5'}]   ['AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'ID', 'IE', 'IL', 'IS', 'IT', 'JO', 'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'OM', 'PA', 'PE', 'PH', 'PL', 'PS', 'PT', 'PY', 'QA', 'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN', 'TR', 'TW', 'US', 'UY', 'VN', 'ZA']    1   157133  TRUE    USAT21907692    https://open.spotify.com/track/6SPgp2qK3fb4wPX1SldrNf   https://api.spotify.com/v1/tracks/6SPgp2qK3fb4wPX1SldrNf    6SPgp2qK3fb4wPX1SldrNf  FALSE   Had Enough (feat. Quavo & Offset)   64  https://p.scdn.co/mp3-preview/8ef4943beb019f23b02252aab0b36c313ff31415?cid=a98a5116ec7149be9fbec4e5ff8afc18 9   track   spotify:track:6SPgp2qK3fb4wPX1SldrNf                                                                            
4   2020-03-18T22:16:21.225Z    https://open.spotify.com/album/7z4GhRfLqfSkqrj5F3Yt2B   https://api.spotify.com/v1/albums/7z4GhRfLqfSkqrj5F3Yt2B    album   spotify:album:7z4GhRfLqfSkqrj5F3Yt2B    album   [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Gso3d4CscCijv0lmajZWs'}, 'href': 'https://api.spotify.com/v1/artists/4Gso3d4CscCijv0lmajZWs', 'id': '4Gso3d4CscCijv0lmajZWs', 'name': 'Don Toliver', 'type': 'artist', 'uri': 'spotify:artist:4Gso3d4CscCijv0lmajZWs'}]    ['AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'ID', 'IE', 'IL', 'IS', 'IT', 'JO', 'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'OM', 'PA', 'PE', 'PH', 'PL', 'PS', 'PT', 'PY', 'QA', 'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN', 'TR', 'TW', 'US', 'UY', 'VN', 'ZA']    https://open.spotify.com/album/7z4GhRfLqfSkqrj5F3Yt2B   https://api.spotify.com/v1/albums/7z4GhRfLqfSkqrj5F3Yt2B    7z4GhRfLqfSkqrj5F3Yt2B  [{'height': 640, 'url': 'https://i.scdn.co/image/ab67616d0000b273da7dc7bd8beaa9bc9ceb8297', 'width': 640}, {'height': 300, 'url': 'https://i.scdn.co/image/ab67616d00001e02da7dc7bd8beaa9bc9ceb8297', 'width': 300}, {'height': 64, 'url': 'https://i.scdn.co/image/ab67616d00004851da7dc7bd8beaa9bc9ceb8297', 'width': 64}]    Heaven Or Hell  3/13/20 day 12  album   spotify:album:7z4GhRfLqfSkqrj5F3Yt2B    [{'external_urls': {'spotify': 'https://open.spotify.com/artist/4Gso3d4CscCijv0lmajZWs'}, 'href': 'https://api.spotify.com/v1/artists/4Gso3d4CscCijv0lmajZWs', 'id': '4Gso3d4CscCijv0lmajZWs', 'name': 'Don Toliver', 'type': 'artist', 'uri': 'spotify:artist:4Gso3d4CscCijv0lmajZWs'}]    ['AD', 'AE', 'AR', 'AT', 'AU', 'BE', 'BG', 'BH', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'ID', 'IE', 'IL', 'IS', 'IT', 'JO', 'JP', 'KW', 'LB', 'LI', 'LT', 'LU', 'LV', 'MA', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'OM', 'PA', 'PE', 'PH', 'PL', 'PS', 'PT', 'PY', 'QA', 'RO', 'SA', 'SE', 'SG', 'SK', 'SV', 'TH', 'TN', 'TR', 'TW', 'US', 'UY', 'VN', 'ZA']    1   180674  FALSE   USAT21904066    https://open.spotify.com/track/47IXLhp3c6mu7NqvpuhuLi   https://api.spotify.com/v1/tracks/47IXLhp3c6mu7NqvpuhuLi    47IXLhp3c6mu7NqvpuhuLi  FALSE   Can't Feel My Legs  67  https://p.scdn.co/mp3-preview/64421f93c1a50553650656789726942083f5c567?cid=a98a5116ec7149be9fbec4e5ff8afc18 6   track   spotify:track:47IXLhp3c6mu7NqvpuhuLi                                                                            
0                                                                                                                                           3/19/20 0.237   https://api.spotify.com/v1/audio-analysis/47IXLhp3c6mu7NqvpuhuLi    0.703   180675  0.655   47IXLhp3c6mu7NqvpuhuLi  0   11  0.199   -6.226  0   0.0782  140.047 4   https://api.spotify.com/v1/tracks/47IXLhp3c6mu7NqvpuhuLi    audio_features  spotify:track:47IXLhp3c6mu7NqvpuhuLi    0.414
0                                                                                                                                           3/19/20 0.0714  https://api.spotify.com/v1/audio-analysis/79EVtighsMYkWahVb9MnF8    0.743   171210  0.753   79EVtighsMYkWahVb9MnF8  3.02E-06    1   0.088   -4.479  1   0.0424  157.047 4   https://api.spotify.com/v1/tracks/79EVtighsMYkWahVb9MnF8    audio_features  spotify:track:79EVtighsMYkWahVb9MnF8    0.695
0                                                                                                                                           3/19/20 0.00981 https://api.spotify.com/v1/audio-analysis/527k23H0A4Q0UJN3vGs0Da    0.629   167916  0.692   527k23H0A4Q0UJN3vGs0Da  0.328   5   0.603   -8.045  1   0.0376  162.948 4   https://api.spotify.com/v1/tracks/527k23H0A4Q0UJN3vGs0Da    audio_features  spotify:track:527k23H0A4Q0UJN3vGs0Da    0.453
0                                                                                                                                           3/19/20 0.262   https://api.spotify.com/v1/audio-analysis/6SPgp2qK3fb4wPX1SldrNf    0.748   157133  0.789   6SPgp2qK3fb4wPX1SldrNf  0   2   0.13    -4.579  1   0.103   147.957 4   https://api.spotify.com/v1/tracks/6SPgp2qK3fb4wPX1SldrNf    audio_features  spotify:track:6SPgp2qK3fb4wPX1SldrNf    0.671
0                                                                                                                                           3/19/20 0.237   https://api.spotify.com/v1/audio-analysis/47IXLhp3c6mu7NqvpuhuLi    0.703   180675  0.655   47IXLhp3c6mu7NqvpuhuLi  0   11  0.199   -6.226  0   0.0782  140.047 4   https://api.spotify.com/v1/tracks/47IXLhp3c6mu7NqvpuhuLi    audio_features  spotify:track:47IXLhp3c6mu7NqvpuhuLi    0.414

添加的数据从new行开始,在数据集的末尾,而不是附加到每一行...

[如果有人可以指出我出了问题的地方,我会很沮丧D:

python pandas api dataframe spotipy
1个回答
1
投票

只是警告,我在写这个假设时假设pddf ['track.uri']和audio_features ['uri']是两个数据帧之间的公共列。如果我误解了数据的结构,则可能需要调整示例中使用的特定名称。

好的,所以您可能遇到的第一个问题与pd.concat()的关系较小,而与您解决此问题的方式关系较大。如果可以,请尝试一次生成包含音频功能的DataFrame,而不是在每个循环中生成DataFrame。首先,获取您需要使用的所有轨道uri的列表。然后,您可以使用循环创建列表列表(甚至更好的是,元组列表)。 然后,您可以将其转换为DataFrame。

为了将其实际转换为DataFrame,通常最好使用merge将它们加入到诸如track uri的通用键上。在这种情况下:

pddf = pddf.merge(audio_features,left_on='track.uri',right_on='uri')
热门问题
推荐问题
最新问题