Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

436
Visualizações
Data loading on MongoDB server works from jupyter notebook but not from script

I have a dataset stored in a json file and I need to upload it to a MongoDB server. Everything works fine if I upload the data using a Jupyter notebook, but not if I use a python script instead. The code is exactly the same. How do you suggest fixing this?

Here is the code:

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()

Here is a screenshot of the python script and of the jupyter notebook. I'm running the notebook using Visual Studio.

enter image description here enter image description here

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Replace

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

with

collection = prepare_dataframe()

and try runnning your script. __main__ explained here pretty well.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda