Insert Pandas Timestamp Into Mongodb
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 an
Solution 1:
A solution would be that you turn index to str
before attempting to store away in MongoDB, like this:
>> df.index = df.index.astype(str)
>> db.testCollection.insert(df.T.to_dict())
When reading the data out of db again later you can turn index to timestamp:
>> df.index = pd.to_datetime(df.index)
I hope this helps
Post a Comment for "Insert Pandas Timestamp Into Mongodb"