title: NamedTuple to Dataframe
body: <p>I am working on retrieving metadata from youtube channels and it's videos.</p>
  <p>Everything is going fine, but currently I am struggling to put all the information in a <code>dataframe</code> which I need. Here is the following code which I am using from this <code>github</code> <a href="https://gist.github.com/andkamau/0d4e312c97f41a975440a05fd76b1d29" rel="nofollow noreferrer">https://gist.github.com/andkamau/0d4e312c97f41a975440a05fd76b1d29</a></p>
  <pre><code>import urllib.request
  import json
  from bs4 import BeautifulSoup
  from collections import namedtuple
  import pafy
  from pandas import *
  import pandas as pd
  
  df = pd.DataFrame() 
  Video = namedtuple(&quot;Video&quot;, &quot;video_id title duration views thumbnail Description&quot;)
  
  def parse_video_div(div):
      video_id = div.get(&quot;data-context-item-id&quot;, &quot;&quot;)
      title = div.find(&quot;a&quot;, &quot;yt-uix-tile-link&quot;).text
      duration = div.find(&quot;span&quot;, &quot;video-time&quot;).contents[0].text
      views = str(div.find(&quot;ul&quot;, &quot;yt-lockup-meta-info&quot;).contents[0].text.rstrip(&quot; views&quot;).replace(&quot;,&quot;, &quot;&quot;))
      img = div.find(&quot;img&quot;)
      videoDescription = pafy.new(&quot;https://www.youtube.com/watch?v=&quot;+video_id)
      thumbnail = &quot;http:&quot; + img.get(&quot;src&quot;, &quot;&quot;) if img else &quot;&quot;
      Description = videoDescription.description
      l = Video(video_id, title, duration, views, thumbnail, Description)
       
       # storing in the dataframe
       
      df = pd.DataFrame(list(Video(video_id, title, duration, views, thumbnail, Description)))
      return Video(video_id, title, duration, views, thumbnail, Description)
  
  def parse_videos_page(page):
      video_divs = page.find_all(&quot;div&quot;, &quot;yt-lockup-video&quot;)
      return [parse_video_div(div) for div in video_divs]
  
  def find_load_more_url(page):
      for button in page.find_all(&quot;button&quot;):
          url = button.get(&quot;data-uix-load-more-href&quot;)
          if url:
              return &quot;http://www.youtube.com&quot; + url
  
  def download_page(url):
      print(&quot;Downloading {0}&quot;.format(url))
      return urllib.request.urlopen(url).read()
  
  def get_videos(username):
      page_url = &quot;http://www.youtube.com/channel/{0}/videos&quot;.format(username)
      page = BeautifulSoup(download_page(page_url))
      videos = parse_videos_page(page)
      page_url = find_load_more_url(page)
      while page_url:
          json_data = json.loads(str(download_page(page_url).decode(&quot;utf-8&quot;)))
          page = BeautifulSoup(json_data.get(&quot;content_html&quot;, &quot;&quot;))
          videos.extend(parse_videos_page(page))
          page_url = find_load_more_url(BeautifulSoup(json_data.get(&quot;load_more_widget_html&quot;, &quot;&quot;)))
      return videos
  
  if __name__ == &quot;__main__&quot;:
      videos = get_videos(&quot;UC-M9eLhclbe16sDaxLzc0ng&quot;)
      for video in videos:
          print(video)
      print(&quot;{0} videos&quot;.format(len(videos)))
  </code></pre>
  <p>The function <code>parse_video_div(div)</code> is having all the information and my <code>dataframe</code>. But unfortunately the <code>dataframe</code> returns nothing. May be I need to loop the <code>namedtuple</code> somehow.</p>
  <p>Any lead on how I can achieve my <code>dataframe</code> to see my data?</p>