title: Extract Pixels from a pmg file and convert them into a pandas data frame
body: <blockquote>
    <p>I have a directory that has subdirectories each with a bunch of PMG files, I would like to extract the pixels from each image and put them in a pandas data frame.</p>
  </blockquote>
  
  <pre><code>from PIL import Image
  import os
  import pandas as pd
  import numpy as np
  dirs = [r"D:\MSIT\Machine Learning\IMG"+"\\s"+str(i) for i in range(1,41)]
  pixels = list()
  df  = pd.DataFrame(columns = ["f" + str(i) for i in range(1,10305)])
  cols = list(df.columns)
  for directory in dirs:
      for filename in os.listdir(directory):
          im = Image.open(directory + "\\" +filename)
          dims = (list(im.getdata()))
          df2 = pd.Series(dims)
          pixels.append(dims)
  k = 1
  for i in pixels:
      for j in i:
          df2 = pd.Series(j)
          df.append(df2, ignore_index = True)
          print(str(k) + "Done")
          k += 1
  print(df.head())
  df.to_csv('pixel_data.csv') 
  </code></pre>