'Importing functions to ipynb noteboke

I am working on a project and I have created more Jupyter notebooks to specific tasks. I would like to design a summary notebook and import the functions from the previous notebooks. So, I made a simple functions.py program, in which I collected all the useful functions. I am sucessful in importing and calling the functions in the summary notebook, but I am struggling with the additional modules needed to run those functions.

My idea was to import all the necessary modules (such as pandas, numpy etc. ) in the first cell of the summary notebook, and when the imported functions want to use them, that will work. But unfortunately, the only way I can run the functions is to add the import command to each functions in functions.py.

This is the first cell of my summary notebook: The cell to import libraries

Then I call some functions from functions.py: functions

get_files, process_file, to_numeric functions all work with the pandas module, but I had to add "import pandas" to each function in functions.py. So, whilst running the cell, will pandas be imported 3 times?

Although my summary workbook works, I am not convinced there is no easier and more practical way to run it.

Could you give me some good hints, please?



Solution 1:[1]

A better way would be to import the functions at the top of your functions.py file. In this way, whenever you import the functions.py file the other functions will load at the same time. Yes, your Pandas library will be imported 3 times. But it's not a big problem as pointed out by @Ssayan in the comment section.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abhyuday Vaish