How to always import a group of modules in Python

Viewed 71

I use Python to do data analysis, and have a group of functions that I almost always use in my analysis. Is there any way to import the functions that I often use in one line or other easier way?

For example, when I start a new Jupyter Notebook for analysis, I put down a list of imports, such as

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

...

from IPython.display import display, HTML, Markdown

Can I put those imports into a module and just do something like

import often_used_modules

And still be able to use those modules normally?

2 Answers

yes, you can do that

# often_used_imports.py
import ...
...

and to use it:

from often_used_imports import *

This is something you wanted to do but I would not recommend it.

Related