0

I am working on a few different pieces of work at the moment and find that I usually use the same Python libraries to do my analysis.

How can I create a file that lists all of the import statements and runs these in the notebooks to be able to use the functions.

EG. I always use pandas in the notebooks to handle my DataFrames, Is there a way to have the import pandas as pd in a separate file and run this file in all the notebooks to be able to use pd.DataFrame (Without the importation in the individual notebook)

Poisson
  • 1
  • 1
  • Hi, so my understanding is that you are trying to have a file that imports all of the modules for you, so all you have to do is import that file? Sorry if I got this wrong. – HoneyPoop Nov 06 '20 at 11:12
  • Have you seen this? https://stackoverflow.com/questions/18963069/import-modules-when-starting-python-in-windows – Carlo Zanocco Nov 06 '20 at 11:12
  • Possibly duplicate of https://stackoverflow.com/questions/35446211/configuring-jupyter-default-imports – Daweo Nov 06 '20 at 11:18
  • @HoneyPoop This is correct. I am trying to have one file that will be read and loaded to load all required modules. – Poisson Nov 06 '20 at 11:18
  • Alright. Just create a seperate python that imports all of your required modules, and make sure it is in the same folder as your file that you are coding in. then just import the file like a regular module. i.e. if the file was named Imports.py, just import Imports. If that was too vague I can explain more – HoneyPoop Nov 06 '20 at 11:41

1 Answers1

0

From what I can tell, theres one answer I could find that worked. have 2 files: main.py and imports.py

in imports.py:

import numpy as np
import pandas as pd
#  etc...

in main.py:

import imports as im
test = im.np.array([1, 0]) # example of a numpy array, but is applicable to im.pd
print(test)