标签:bsp == frame insert enc 标题 panda god col
自己记录下,Dataframe数据需要转成字典,并且保证列标题中不能有 “,”等非string字符。
1 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
标签:bsp == frame insert enc 标题 panda god col
原文地址:https://www.cnblogs.com/dpdwsf/p/11017423.html