Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

435
Views
La carga de datos en el servidor MongoDB funciona desde el cuaderno jupyter pero no desde el script

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.

ingrese la descripción de la imagen aquí ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Reemplazar

 if __name__ == '__main__': collection = prepare_dataframe()

con

 collection = prepare_dataframe()

e intente ejecutar su script. __main__ explicó aquí bastante bien.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!