Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Python Pyforest Library



The Python pyforest library simplifies the process of importing commonly used libraries in data science and machine learning projects. Instead of manually importing each library. The pyforest library bundles them together and allows to access classed and functions from the libraries like NumPy, pandas, matplotlib, seaborn, nltk, and others without explicit import statements.

Installation of pyforest Library

To use pyforest library, you need to install it. You can do this using pip

pip install pyforest

Importing pyforest Library

After installing, you need to import pyforest into your Python script to access the bundled libraries −

import pyforest

Using NumPy with Pyforest

NumPy is a fundamental package for scientific computing in Python. It provides support for arrays and matrices, along with a large collection of mathematical functions to operate on these arrays. Functionalities of NumPy library can be used without importing the numpy package. You just need to import pyforest.

Example

In the following example, we are using the functionalities of numpy using pyforest library −

import pyforest 
a = np.array([[10,20],[30,40]])
print(a)

Output

[[10 20]
 [30 40]]

Using Pandas with Pyforest

Pandas provides high-performance, easy-to-use data structures and data analysis tools. It is particularly used for working with structured (tabular, multidimensional, potentially heterogeneous) and time series data.

Example

In the following example, we are using the functionalities of pandas using pyforest library −

import pyforest
d = {'X': [10, 20, 30], 'Y': [40, 50, 60], 'Z': [70, 80, 90]}
df = pd.DataFrame(d)
print(df)

Output

X  Y  Z
0  10  40  70
1  20  50  80
2  30  60  90

Using NLTK with Pyforest

NLTK (Natural Language Toolkit) is a leading platform for building Python programs to work with human language data.

In the following example, we are using the functionalities of nltk using pyforest library.

Note that − To run the below example, you need to install the following library by using the below installation command −

pip install user -U nltk

To download the nltk data −

import nltk
nltk.downloa('punkt)

Example

import pyforest
from nltk.tokenize import word_tokenize
 
data = "All apples are red in colour"
print(word_tokenize(data))

Output

['All', 'apples', 'are', 'red', 'in', 'colour']

Using Matplotlib with Pyforest

Matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. It can be used in Python scripts, shell, web application servers, and various graphical user interface toolkits.

Example

In the following example, we are using the functionalities of matplotlib using pyforest library.

import pyforest
x = [10, 20, 30, 40, 50]
y = [1, 2, 3, 4, 5]
 
plt.plot(x, y)
plt.show()

Output

Pyforest
python_projects_from_basic_to_advanced.htm
Advertisements