How do you save a pandas dataframe to mongodb using the recommended time based bucketing? The data in this case has an index with datetime, and columns with integers. I figured out how to create single documents for each timestamp, but can't figure out how to arrange the dataframe or loop through the dataframe to save a minutes worth of data it one document.
client = MongoClient('localhost', 27017)
db = client.testing
data_df = pd.read_pickle('fake_data.pkl')
for i, row in tqdm(enumerate(data_df.itertuples(), 1)):
query = {'Timestamp': getattr(row, 'Index')}
data = {'$set':
{'Timestamp': getattr(row, 'Index'),
'A': getattr(row, 'A'),
'B': getattr(row, 'B'),
'C': getattr(row, 'C'),
'D': getattr(row, 'B')
}
}
db.single_doc_collection.update_one(query, data, upsert=True)