title: Insert Pandas Timestamp into Mongodb
body: <p>I'm trying to insert a Pandas DataFrame into Mongodb using PyMongo. </p>
  
  <pre><code>df.head()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/zGFj5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zGFj5.png" alt="enter image description here"></a></p>
  
  <p>Because the index if the Pandas DataFrame is a <code>DatetimeIndex</code>, converting the DataFrame to a <code>dict</code> and inserting it to Mongodb:</p>
  
  <pre><code>db.testCollection.insert( df.T.to_dict() )
  </code></pre>
  
  <p>gives rise to an error:</p>
  
  <pre><code>InvalidDocument: documents must have only string keys, key was Timestamp('2016-04-07 09:30:00')
  </code></pre>
  
  <p>How can we convert the <code>DatetimeIndex</code> to something else that can be inserted into Mongodb, and later still be able to be converted back to a DatetimeIndex when reading from Mongodb?</p>