Created
April 13, 2017 22:58
-
-
Save shinshin86/a650ee1227be2105eb3069d076ec3f32 to your computer and use it in GitHub Desktop.
This is sample of mongo data to data frame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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