Skip to content

Instantly share code, notes, and snippets.

@shinshin86
Created April 13, 2017 22:58
Show Gist options
  • Save shinshin86/a650ee1227be2105eb3069d076ec3f32 to your computer and use it in GitHub Desktop.
Save shinshin86/a650ee1227be2105eb3069d076ec3f32 to your computer and use it in GitHub Desktop.
This is sample of mongo data to data frame
import pymongo
import json
import pandas as pd
from bson.json_util import dumps
def get_co():
client = pymongo.MongoClient(hostname, port) # hostname & port
db = client.dbname # db name
collection = db.collection_name # collection name
return collection
def get_all_data():
return get_co().find()
def get_df():
d = get_all_data()
data = pd.read_json(dumps(d))
return data
# get data frame
df = get_df()
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment