Importing data from MongoDB into Python (Pandas)


import modules

import pymongo
import pandas as pd
from pymongo import MongoClient

connect to mongo, import collection into Pandas dataframe

client = MongoClient()
#point the client at mongo URI
client = MongoClient('Mongo URI')
#select database
db = client['database_name']
#select the collection within the database
test = db.test
#convert entire collection to Pandas dataframe
test = pd.DataFrame(list(test.find()))


Ace your next data science interview

Get better at data science interviews by solving a few questions per week



Find a bug? Submit a suggested change on Github, or message me on Twitter.