How do I create a shortcut to import most used python modules?

夙愿已清 提交于 2021-01-05 10:53:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!