当前位置:Gxlcms > 数据库问题 > Dataframe数据直接存入mongodb

Dataframe数据直接存入mongodb

时间:2021-07-01 10:21:17 帮助过:432人阅读

import pymongo 2 import pandas as pd 3 4 5 def main() 6   mongo_client = pymongo.MongoClient(localhost, 27017) 7   db = mongo_client[mydb] 8   mycol = db[your_col] 9   data = your_df.to_dict(orient=record)  10   mycol.insert_many(data) 11 12 if __name__ == ‘__main__:
13   main()

 

参考:

https://stackoverflow.com/questions/49221550/pandas-insert-a-dataframe-to-mongodb?r=SearchResults

http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_dict.html

 

Dataframe数据直接存入mongodb

标签:bsp   ==   frame   insert   enc   标题   panda   god   col   

人气教程排行