Home >Backend Development >Python Tutorial >Task-Python Packages

Task-Python Packages

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-09 19:48:12306browse

Few Python Packages

Progress Bar and TQDM:
To implement progress bars for tasks such as loops, file processing, or downloads.

from progress.bar import ChargingBar
bar = ChargingBar('Processing', max=20)
for i in range(20):
    # Do some work
    bar.next()
bar.finish()

Output:

Processing ████████████████████████████████ 100%

TQDM: Similar to progress bar but its more simple to setup than progress bar.

from tqdm import tqdm
import time

for i in tqdm(range(100)):
    time.sleep(0.1)

Output:

100%|██████████████████████████████████████| 100/100 [00:00<00:00, 18784.11it/s]

Matplotlib:

Matplotlib is used for creating static, animated, and interactive visualizations.

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

plt.plot(x, y, label='Linear Growth', color='blue', linestyle='--', marker='o')
plt.title("Line Plot Example")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.legend()
plt.show()

Output:

Task-Python Packages

Numpy:
NumPy (Numerical Python) is a fundamental Python library for numerical computing. It provides support for working with large, multi-dimensional arrays (like 1-D,2-D,3-D) and matrices, along with a collection of mathematical functions to operate on these arrays efficiently.

Example:

import numpy as np

# 1D array
arr1 = np.array([1, 2, 3, 4])

# 2D array
arr2 = np.array([[1, 2], [3, 4]])

print(arr1, arr2)

Output:

[1 2 3 4] [[1 2]
 [3 4]]

Pandas:
It is used for data manipulation and analysis with Series(lists) and DataFrame(table or spreadsheet).

Example:

import pandas
x=[1,2,3]
y=pandas.Series(x,index=["no1","no2","no3"])
print(y)

Output:

no1    1
no2    2
no3    3
dtype: int64

The above is the detailed content of Task-Python Packages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn