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

Task-Python Packages

Mary-Kate Olsen
Release: 2024-12-09 19:48:12
Original
374 people have browsed it

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()
Copy after login

Output:

Processing ████████████████████████████████ 100%
Copy after login

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)
Copy after login

Output:

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

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()
Copy after login

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)
Copy after login

Output:

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

Copy after login

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)
Copy after login

Output:

no1    1
no2    2
no3    3
dtype: int64
Copy after login

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

source:dev.to
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template