# intialize list to store video captions transcript_text_list = [] # loop through each row of dataframe for i in range(len(df)): # try to extract captions try: # get transcript transcript = YouTubeTranscriptApi.get_transcript(df['video_id'][i]) # extract text transcript transcript_text = extract_text(transcript) # if not captions available set as n/a except: transcript_text = "n/a" # append transcript text to list transcript_text_list.append(transcript_text)