Insert xlsx file data to Mongo Collection with Pandas

Insert xls, csv data to mongo db with python, pandas.

import pandas as pd
import YourMongoConnection
import json

if __name__ == "__main__":
    df = pd.read_excel('path/to/data.xlsx')
    mog_connector = YourMongoConnection(credentials)
    collection = mog_connector.client['db_name']['collection_name']
    docs = json.loads(df.T.to_json()).values()
    collection.insert_many(docs)

Insert xlsx file data to Mongo Collection with Pandas
Show Buttons
Hide Buttons