I made a second API call which consists of the statistics of the youtube channels ids i received from my first API call and i inserted it into the for loop i had initially made in order to organize the data from my first API call. Here is the code :
#collecting snippet datafor video in response['items']: if video['id']['kind'] == "youtube#video": video_id = video['id']['videoId'] video_title = video['snippet']['title'] video_description = video['snippet']['description'] channel_title = video['snippet']['channelTitle'] date_upload = video['snippet']['publishedAt'] date_upload = str(date_upload).split('T')[0] #collecting statistics data #2nd API CALL video_stats_url = "https://www.googleapis.com/youtube/v3/videos? part=statistics&key="+API_KEY video_ids = ['xC-c7E5PK0Y','X3paOmcrTjQ','-ETQ97mXXF0','FvGRKQipTP8','LHBE6Q9XlzI', ] for vid in video_ids: video_stats_url += "&id=" + vid response_2 = requests.get(video_stats_url).json() view_count = response_2['items'][0]['statistics']['viewCount'] like_count = response_2['items'][0]['statistics']['likeCount'] favorite_count = response_2['items'][0]['statistics']['favoriteCount'] comment_count = response_2['items'][0]['statistics']['commentCount']
Then after this code, i saved it into a pandas dataframe
I was hoping each unique statistics from the 2nd API call will be applied into the DataFrame, which contains, like_count, view_count, favorite_count and comment_count. However, i see duplicates values of those features applied in other rows. Here's a look showing different youtube channels with identical views, likes and comment counts. I know having [0] in the statistics variable is the problem, but when i remove it, i get an error. Thank you.
Please help, i'm a newbie to coding.