惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - ReturnHome

shell脚本 sql窗口函数 sql常用 大数据面试问题 金融行业测试总结 电商高并发高库存系统测试总结 AI测试 大模型性能测试 100 条大模型人工测试用例 记忆管理 多智能体协作 Elasticsearch(ES) 知识检索 jmeter计算模型token AI提示词链 详解https协议和http协议的区别和底层工作原理 请求区别 app测试注意点 TCP的三次握手和四次挥手 常用的中间件
Python常用库和方法
ReturnHome · 2026-04-10 · via 博客园 - ReturnHome

import requests

res = requests.get("https://www.baidu.com")

res = requests.post("https://xxx.com/api", data={"key": "value"})

params = {"page": 1, "size": 10} res = requests.get("https://xxx.com/list", params=params)

headers = {"User-Agent": "Mozilla/5.0"} res = requests.get("https://xxx.com", headers=headers)

res.status_code # 状态码 200=成功

res.text # 文本内容(html/json字符串)

res.json() # 直接转成字典(接口必用)

res.headers # 响应头

res.cookies # cookies

# 超时设置

res = requests.get(url, timeout=5)

# 关闭警告(访问不安全https)

requests.packages.urllib3.disable_warnings()

res = requests.get(url, verify=False)

pip install pandas

import pandas as pd

# 读取 Excel

df = pd.read_excel("data.xlsx")

# 读取 CSV

df = pd.read_csv("data.csv")

# 读取 SQL

df = pd.read_sql("select * from table", conn)

df.head() # 前5行

df.tail() # 后5行

df.info() # 字段类型

df.describe() # 统计(均值、最大最小)

df.shape # (行数, 列数)

df.columns # 列名

df.dtypes # 每列类型

df.dropna() # 删除空值

df.fillna(0) # 空值填充0

df.rename(columns={"old":"new"}) # 改列名

df.drop(["col1"], axis=1) # 删除列

df.sort_values("age") # 排序

df.drop_duplicates() # 去重

df.groupby("class")["score"].mean() # 按班级求平均分

df.to_excel("new.xlsx", index=False)

1、上下拼接(行拼接)concat

两个表结构一样,像 Excel 复制粘贴到下面。

import pandas as pd

df1 = pd.read_excel("表1.xlsx")

df2 = pd.read_excel("表2.xlsx")

# 上下拼接

df = pd.concat([df1, df2], ignore_index=True)

ignore_index=True:重新生成行号(推荐)

不加的话,行号会保留原来的,可能重复

2、左右合并(列拼接)merge

按某个共同字段(如 id、姓名、单号)关联,类似 SQL 的 join。

(1)内连接(只保留两边都有的)

df = pd.merge(df1, df2, on='订单号', how='inner')

(2)左连接(以左边表为主)

df = pd.merge(df1, df2, on='订单号', how='left')

(3)右连接 / 全连接

df = pd.merge(df1, df2, on='订单号', how='right')

df = pd.merge(df1, df2, on='订单号', how='outer')

(4)如果两个表关键字段名不一样

df = pd.merge(df1, df2, left_on='id', right_on='user_id', how='left')

3、简单横向拼接(不按关键字,直接拼列)

df = pd.concat([df1, df2], axis=1)