A better way to load MongoDB data to a DataFrame using Pandas and PyMongo?

前端 未结 4 1173
故里飘歌
故里飘歌 2020-12-29 13:59

I have a 0.7 GB MongoDB database containing tweets that I\'m trying to load into a dataframe. However, I get an error.

MemoryError:    

My

4条回答
  •  半阙折子戏
    2020-12-29 14:24

    The from_records classmethod is probably the best way to do it:

    from pandas import pd
    import pymongo
    
    client = pymongo.MongoClient()
    data = db.mydb.mycollection.find() # or db.mydb.mycollection.aggregate(pipeline)
    
    df = pd.DataFrame.from_records(data)
    

提交回复
热议问题