title: Insert a Pandas Dataframe into mongodb using PyMongo
body: <p>What is the quickest way to insert a pandas DataFrame into mongodb using <code>PyMongo</code>?</p>
  
  <p><strong>Attempts</strong></p>
  
  <pre><code>db.myCollection.insert(df.to_dict())
  </code></pre>
  
  <p>gave an error </p>
  
  <blockquote>
    <p><code>InvalidDocument: documents must have only string keys, the key was
    Timestamp('2013-11-23 13:31:00', tz=None)</code></p>
  </blockquote>
  
  <hr>
  
  <pre><code> db.myCollection.insert(df.to_json())
  </code></pre>
  
  <p>gave an error </p>
  
  <blockquote>
    <p><code>TypeError: 'str' object does not support item assignment</code></p>
  </blockquote>
  
  <hr>
  
  <pre><code> db.myCollection.insert({id: df.to_json()})
  </code></pre>
  
  <p>gave an error </p>
  
  <p><code>InvalidDocument: documents must have only string a keys, key was &lt;built-in function id&gt;</code></p>
  
  <hr>
  
  <p><strong>df</strong></p>
  
  <pre><code>&lt;class 'pandas.core.frame.DataFrame'&gt;
  DatetimeIndex: 150 entries, 2013-11-23 13:31:26 to 2013-11-23 13:24:07
  Data columns (total 3 columns):
  amount    150  non-null values
  price     150  non-null values
  tid       150  non-null values
  dtypes: float64(2), int64(1)
  </code></pre>