问题
I am looking for a way to automatically (or as a shortcut) import a set of python modules in a jupyter notebook so that I don't have to import them every time I create a new notebook
I am finding it very repetitive to import these modules to every notebook. The closest thing I could think here is creating a python file and importing that as a module, but I am looking for something more flexible in Jupyter-notebook
# Example Code
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
What could be an easy way to import these long list of modules? as I am finding myself repeating the whole set of modules in every notebook.
回答1:
You could have a file frequently_imported_modules.py
where you have literally only the imports you use frequently and then import all these in your new script like so:
from frequently_imported_modules import *
Whether this is a good practice? I don't think so.
来源:https://stackoverflow.com/questions/56089179/how-do-i-create-a-shortcut-to-import-most-used-python-modules