Tengo un conjunto de datos almacenado en un archivo json y necesito cargarlo en un servidor MongoDB. Todo funciona bien si cargo los datos usando un cuaderno Jupyter, pero no si uso un script de python en su lugar. El código es exactamente el mismo. ¿Cómo sugieres arreglar esto?
Aquí está el código:
import pandas as pd import pymongo from pymongo import MongoClient import json import DNS # Function to upload the dialogue lines to MongoDB Server def prepare_dataframe(): dialogue_edited = pd.read_json("5lines1response_random100from880_cleaned.json") dialogue_edited.reset_index(inplace=True) data_dict = dialogue_edited.to_dict("records")# Insert collection # To communicate with the MongoDB Server cluster = MongoClient() db = cluster['DebuggingSystem'] collection = db['MCS_dialogue'] collection.insert_many(data_dict) return collection if __name__ == '__main__': collection = prepare_dataframe()
Aquí hay una captura de pantalla del script de python y del cuaderno jupyter. Estoy ejecutando el cuaderno usando Visual Studio.