The user can also import a Utility file by using the Utility option provided inside a Notebook. Refer the Utility Notebook Operation page to understand it in details.
Sample Utility Script
Please use the below-given sample Utility script to explore and use the Utility option provided in the Data Science Lab.
# importing employee.py as a module in DS Lab Notebook.
import employee
import time
import logging
import pandas as pd
from pymongo import MongoClient
def run_scripts(conn_str, database, collection):
conn_str = conn_str
database = database
collection = collection
client = MongoClient(conn_str)
db = client[database]
collection = db[collection]
res = employee.emp_data()
for i in res:
salary = i.get('salary', 0)
i['status'] = 'rich' if salary > 50000 else ('middle_class' if 25000 < salary < 50000 else 'poor')
logging.info(i)
print(i)
collection.insert_many(res)
print(f"Inserted {len(res)} rows into MongoDB")
logging.info(f"Inserted {len(res)} rows into MongoDB")
#The variable 'res' in this script holds the results derived from the code written in the utility file.