Skip to content

Instantly share code, notes, and snippets.

@6mini
Last active November 6, 2021 15:22
Show Gist options
  • Save 6mini/264b860876ab3f8e532018d424f8b2ea to your computer and use it in GitHub Desktop.
Save 6mini/264b860876ab3f8e532018d424f8b2ea to your computer and use it in GitHub Desktop.
Insert in the csv file MongoDB using Pandas.
import pandas as pd
from pymongo import MongoClient
import json
data = json.loads(pd.read_csv('csv.csv').to_json(orient='records'))
coll = MongoClient(MONGO_URI)[DATABASE_NAME][COLLECTION_NAME]
coll.remove()
coll.insert_many(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment