In Python, How do you use a loop to create a dataframe?
Based on what I know about youtube APIs return objects, the values of 'title' , 'videoId' and 'publishedAt' are strings. A strategy of making a single df from these strings are:
- Store these strings in a list. So you will have three lists.
- Convert the lists into a df
You will get a df with x rows, based on x values that are retrieved.
Example:
import pandas as pd
x=0
video_title = []
video_id = []
date_created = []
while x < len(response['items']):
video_title.append (response['items'][x]['snippet']['title'])
video_id.append (response['items'][x]['id']['videoId'])
date_created.append (response['items'][x]['snippet']['publishedAt'])
x=x+1
#print(video_title, video_id)
df = pd.DataFrame({'video_title': video_title,'video_id':
video_id, 'date_created': date_created})