在pandas中加载mongodb中的数据

#导入相应的包
import pymongo
import pandas as pd
from pandas import Series,DataFrame
#连接数据库
#mongo_url = f'mongodb://{username}:{password}@%{host}:{port}/{db}'
client = pymongo.MongoClient('localhost',27017)
#加载库
ganji = client['ganji']  
#加载collection
info = ganji['info']   
#加载数据
data = DataFrame(list(info.find()))
#删除不想要的字段
data_new = data.T.drop(['_id','url','title'])
print(data_new)
posted @ 2019-06-20 15:37  洋洋同学  阅读(599)  评论(0编辑  收藏  举报