#-*- coding:utf-8 -*-
import sys
import pandas as pd
from pymongo import MongoClient
reload(sys)
sys.setdefaultencoding('utf-8')
class MongoBase:
def __init__(self,collection):
self.collection=collection
self.OpenDB()
def OpenDB(self):
user='******'
passwd='******'
host='******'
port='******'
auth_db='******'
uri = "mongodb://"+user+":"+passwd+"@"+host+":"+port+"/"+auth_db+"?authMechanism=SCRAM-SHA-1"
self.con = MongoClient(uri, connect=False)
self.db=self.con['qq']
self.collection=self.db[self.collection]
def closeDB(self):
self.con.close()
if __name__ =='__main__':
query={'time':{'$regex':'2017-01-19'}}
mongo=MongoBase('******')
cursor = mongo.collection.find(query)
df = pd.DataFrame(list(cursor))
mongo.closeDB()
del df['_id']
print df
Pandas读取MongoDB数据库到DataFrame
最新推荐文章于 2024-04-10 09:52:37 发布