-
Notifications
You must be signed in to change notification settings - Fork 3
MongoDB and pandas
stanislawbartkowski edited this page May 31, 2021
·
2 revisions
This article contains tips on how to access MongoDB using Python3
https://docs.h2o.ai/h2o/latest-stable/h2o-docs/downloading.html
https://pymongo.readthedocs.io/en/stable/tutorial.html
sudo pip3 install pandas
sudo pip3 install matplotlib
sudo pip3 install pymongo
sudo pip3 install datatable
sudo pip3 install -f https://docs.h2o.ai/h2o/latest-stable/h2o-docs/downloading.html h2o
The prerequisites required depends on the Jupyter image used. If necessary, load them using !conda command
import sys
!conda install --yes --prefix {sys.prefix} pymongo
from pymongo import MongoClient
import pandas as pd
MONGO_CONNECTION_STRING = "mongodb://admin:secret@adown-inf:27017/querydb?authSource=testdb"
MONGO_DB = "testdb"
MONGO_COLLECTION = "orders"
client= MongoClient(MONGO_CONNECTION_STRING)
db = client.get_database(MONGO_DB)
coll = db.get_collection(MONGO_COLLECTION)
#docs = coll.find()
docs = coll.find_one()
df = pd.DataFrame.from_dict(docs)
print(df.dtypes)
print(df.size)
#for doc in df.items():
# print(doc)
for row in df.iterrows() : print(row)