Files
python/Packages/readme.md
2025-09-08 21:11:28 +08:00

112 lines
6.3 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

好的,我给你整理一份 **Python 常用第三方包和标准库简介**,按用途分类,包含功能和简单示例,方便你快速了解和查阅。
---
# 1⃣ 科学计算与数据分析
| 包名 | 功能 | 示例 |
| -------------- | -------------------- | ----------------------------------------------------- |
| **NumPy** | 高性能数组运算、矩阵运算 | `import numpy as np; a = np.array([1,2,3])` |
| **Pandas** | 数据处理与分析DataFrame 操作 | `import pandas as pd; df = pd.DataFrame({'a':[1,2]})` |
| **SciPy** | 科学计算函数库,线性代数、优化、信号处理 | `from scipy import optimize; optimize.minimize(...)` |
| **Matplotlib** | 数据可视化,绘图 | `import matplotlib.pyplot as plt; plt.plot([1,2,3])` |
| **Seaborn** | 高级可视化,基于 Matplotlib | `import seaborn as sns; sns.heatmap(data)` |
---
# 2⃣ 机器学习与深度学习
| 包名 | 功能 | 示例 |
| ---------------------- | ------------------ | ----------------------------------------------------- |
| **scikit-learn** | 经典机器学习算法 | `from sklearn.ensemble import RandomForestClassifier` |
| **TensorFlow** | 深度学习框架 | `import tensorflow as tf; tf.constant([1,2])` |
| **PyTorch** | 深度学习框架,动态图 | `import torch; x = torch.tensor([1,2])` |
| **Keras** | 高级神经网络接口(常与 TF 搭配) | `from keras.models import Sequential` |
| **XGBoost / LightGBM** | 提升树算法,常用于 Kaggle | `import xgboost as xgb` |
---
# 3⃣ 数据获取与处理
| 包名 | 功能 | 示例 |
| ----------------- | ---------------- | ------------------------------------------------------------------------- |
| **requests** | HTTP 请求 | `import requests; r = requests.get(url)` |
| **BeautifulSoup** | HTML / XML 解析 | `from bs4 import BeautifulSoup; soup = BeautifulSoup(html,'html.parser')` |
| **lxml** | 高效 HTML / XML 解析 | `from lxml import etree` |
| **json** | JSON 数据处理(标准库) | `import json; data = json.loads(json_str)` |
| **csv** | CSV 文件操作(标准库) | `import csv; reader = csv.reader(f)` |
---
# 4⃣ 系统与文件操作
| 包名 | 功能 | 示例 |
| -------------- | ------------------ | ------------------------------------------- |
| **os** | 系统操作、文件路径(标准库) | `import os; os.listdir('.')` |
| **sys** | Python 解释器相关操作 | `import sys; sys.argv` |
| **shutil** | 高级文件操作,如复制、移动 | `import shutil; shutil.copy('a','b')` |
| **pathlib** | 面向对象的路径操作Python3 | `from pathlib import Path; p = Path('.')` |
| **subprocess** | 执行外部命令 | `import subprocess; subprocess.run(['ls'])` |
---
# 5⃣ Web 开发
| 包名 | 功能 | 示例 |
| ------------ | ---------- | ------------------------------------------------ |
| **Flask** | 轻量 Web 框架 | `from flask import Flask; app = Flask(__name__)` |
| **Django** | 全功能 Web 框架 | `django-admin startproject mysite` |
| **FastAPI** | 高性能 API 框架 | `from fastapi import FastAPI; app = FastAPI()` |
| **requests** | HTTP 客户端 | 同上 |
---
# 6⃣ 图像与多媒体处理
| 包名 | 功能 | 示例 |
| --------------------- | ------ | -------------------------------------------------- |
| **Pillow** | 图像处理 | `from PIL import Image; img = Image.open('a.jpg')` |
| **OpenCV (cv2)** | 计算机视觉 | `import cv2; img = cv2.imread('a.jpg')` |
| **matplotlib.pyplot** | 简单图像显示 | `plt.imshow(img)` |
---
# 7⃣ 常用工具库
| 包名 | 功能 | 示例 |
| ------------- | -------- | ----------------------------------------------------- |
| **re** | 正则表达式 | `import re; re.findall(r'\d+', 'abc123')` |
| **datetime** | 日期与时间处理 | `import datetime; datetime.datetime.now()` |
| **random** | 随机数 | `import random; random.randint(1,10)` |
| **itertools** | 高级迭代工具 | `import itertools; itertools.combinations([1,2,3],2)` |
| **functools** | 函数工具,如缓存 | `from functools import lru_cache` |
---
# 8⃣ 数据序列化与持久化
| 包名 | 功能 | 示例 |
| ---------- | ------------ | ----------------------------------------- |
| **pickle** | Python 对象序列化 | `import pickle; pickle.dump(obj,f)` |
| **shelve** | 类似字典的简单数据库 | `import shelve; db = shelve.open('data')` |
| **json** | JSON 序列化 | 同上 |
---
# 🔹 总结
1. **科学计算** → NumPy, Pandas, SciPy, Matplotlib, Seaborn
2. **机器学习/深度学习** → scikit-learn, TensorFlow, PyTorch, Keras, XGBoost
3. **数据获取** → requests, BeautifulSoup, lxml, json, csv
4. **系统/文件操作** → os, sys, shutil, pathlib, subprocess
5. **Web 开发** → Flask, Django, FastAPI
6. **图像处理** → Pillow, OpenCV
7. **工具函数** → re, datetime, random, itertools, functools
8. **数据持久化** → pickle, shelve, json
---
我可以帮你画一张 **Python 常用包分类全景图**,把这些包按用途分层,直观展示,方便快速记忆。
你希望我画吗?