I'm trying to insert a Pandas DataFrame into Mongodb using PyMongo.
df.head()
Because the index if the Pandas DataFrame is a DatetimeIndex
, converting the DataFrame to a dict
and inserting it to Mongodb:
db.testCollection.insert( df.T.to_dict() )
gives rise to an error:
InvalidDocument: documents must have only string keys, key was Timestamp('2016-04-07 09:30:00')
How can we convert the DatetimeIndex
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?