title: Tensorflow - input from DataFrame using batching and sparse/categorical data
body: <p>I have a relatively small dataset that I load into memory using a pandas DataFrame. I'd like to feed this data to a tensorflow model using batching, while maintaining support for sparse (categorical) columns. I'd also like to avoid having to serialize my data to disk in some other format. Although this doesn't seem too complicated I couldn't find a good example in the docs and had a pretty tough time designing a suitable <code>input_fn</code> myself.</p>
  
  <p>An toy example dataset would be:</p>
  
  <pre><code>df = pd.DataFrame(np.random.randint(1, 4, [7, 3]), columns=['c0', 'c1', 'c2'])
  df['c1'] = df['c1'].astype(str) + 'g'
  df['c2'] = (df['c2'] &gt; 2.5).astype(int)
  
  &gt;&gt;&gt; df
     c0  c1  c2
  0   3  3g   1
  1   1  1g   0
  2   1  2g   0
  3   2  2g   1
  4   2  3g   0
  5   1  3g   0
  6   3  1g   0
  </code></pre>
  
  <p>where <code>c0</code> is a dense numeric column, <code>c1</code> is a categorical column, and <code>c2</code> is a binary label column.</p>
  
  <p>My solution is below, anything prettier and/or more efficient would be great.</p>