The following are some of the most useful tools for Python data processing and visualization.


Have you ever encountered the problem that every time you restart a modeling process or analysis process, you re-type import or copy in the previous import code? Although the knurled knurls are already well known, they consume unnecessary time.

This article introduces you to a python library that can be lazy: PyForest

A sample

As you can see, there is no import at the beginning, so you can still use common libraries.

The installation

Python3.6 or later is required, and then the terminal runs:

pip install pyforestCopy the code


Method of use

Very simple!!

One line of code.

from pyforest import *Copy the code

If you’re using Jupyter or IPython, you can even skip this line because PyForest adds itself to the auto-start.

Furthermore, after the script is complete, all import statements can be exported as follows:

active_imports()Copy the code

With this directive, we can see all the libraries involved in the script that I have omitted.

Well, you might ask, what if the required library isn’t in PyForest?

First, PyForest supports most popular data science libraries such as Pandas, Numpy, Matplotlib, Seaborn, SkLearn, TensorFlow, etc., as well as common auxiliary libraries such as OS, SYS, RE, pickle, etc.

### Data Wranglingpd = LazyImport("import pandas as pd")np = LazyImport("import numpy as np")dd = LazyImport("from dask import dataframe as dd")SparkContext = LazyImport("from pyspark import SparkContext")load_workbook = LazyImport("from openpyxl import load_workbook")### Data Visualization and Plottingmpl = LazyImport("import matplotlib as mpl")plt = LazyImport("import matplotlib.pyplot as plt")sns = LazyImport("import seaborn as sns")py = LazyImport("import plotly as py")go = LazyImport("import plotly.graph_objs as go")px = LazyImport("import plotly.express as px")dash = LazyImport("import dash")bokeh = LazyImport("import bokeh")alt = LazyImport("import altair as alt")pydot = LazyImport("import pydot")# statisticsstatistics = LazyImport("import statistics")### Machine Learningsklearn = LazyImport("import sklearn")OneHotEncoder = LazyImport("from sklearn.preprocessing import OneHotEncoder")TSNE = LazyImport("from sklearn.manifold import TSNE")train_test_split = LazyImport("from sklearn.model_selection import train_test_split")svm = LazyImport("from sklearn import svm")GradientBoostingClassifier = LazyImport(    "from sklearn.ensemble import GradientBoostingClassifier")GradientBoostingRegressor = LazyImport(    "from sklearn.ensemble import GradientBoostingRegressor")RandomForestClassifier = LazyImport(    "from sklearn.ensemble import RandomForestClassifier")RandomForestRegressor = LazyImport("from sklearn.ensemble import RandomForestRegressor")TfidfVectorizer = LazyImport(    "from sklearn.feature_extraction.text import TfidfVectorizer")# TODO: add all the other most important sklearn objects# TODO: add separate sections within machine learning viz. Classification, Regression, Error Functions, Clustering# Deep Learningtf = LazyImport("import tensorflow as tf")keras = LazyImport("import keras")# NLPnltk = LazyImport("import nltk")gensim = LazyImport("import gensim")spacy = LazyImport("import spacy")re = LazyImport("import re")### Helpersys = LazyImport("import sys")os = LazyImport("import os")re = LazyImport("import re")glob = LazyImport("import glob")Path = LazyImport("from pathlib import Path")pickle = LazyImport("import pickle")dt = LazyImport("import datetime as dt")tqdm = LazyImport("import tqdm")Copy the code

Second, it doesn’t matter if you don’t have one, PyForest supports adding libraries to it. To do this, simply go to the user_imports. Py file in the PyForest library and add a statement like this:

################################ User-specific imports ################################# You can save your own imports in ~/.pyforest/user_imports.py# Please note: imports in ~/.pyforest/user_imports.py take precedence over the# imports above.Copy the code

So we can add our own set of universal import according to our own usage habits, which is fantastic.

Some students may also ask, will all the libraries be added to run slower?

The answer is no, because the program will only import if you later use the included library in PyForest, otherwise it won’t.

The above is lazy artifact introduction and use method, interested partners can try!