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

推荐订阅源

C
Cisco Blogs
Schneier on Security
Schneier on Security
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Scott Helme
Scott Helme
Webroot Blog
Webroot Blog
Project Zero
Project Zero
Google Online Security Blog
Google Online Security Blog
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
Hacker News: Ask HN
Hacker News: Ask HN
PCI Perspectives
PCI Perspectives
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News | PayPal Newsroom
Help Net Security
Help Net Security
The Hacker News
The Hacker News
H
Heimdal Security Blog
O
OpenAI News
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 叶小钗
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
I
Intezer
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security Affairs
P
Proofpoint News Feed
S
Secure Thoughts
腾讯CDC
Google DeepMind News
Google DeepMind News
量子位
罗磊的独立博客

博客园 - 三叶草╮

DeepAgents 长期记忆相关组件详解 DeepAgents 长期记忆 笔记 Python 机器学习03 - 常见分类算法 Python 机器学习02 - 常见分类算法 Python uv 包管理 Python机器学习01 - Sklearn Python高级编程笔记 (线程/进程/协程) Python高级编程笔记 Python 基础笔记 Python Pandas Python playwright 笔记 pipreqs:快速准确生成当前项目的requirements.txt,还有和freeze的对比 WPF 4款 UI 库 C# Selenium [转]在WPF中自定义控件 UserControl [转]WPF的依赖属性是怎么节约内存的 [转]WPF中的导航框架 [转]C#对Excel报表进行操作(读写和基本操作) C# 模拟http请求网页数据 [网页爬虫]
Pandas 常用操作 (缺失值处理/排序/字符串处理/Index/Merge/合并)
三叶草╮ · 2025-03-04 · via 博客园 - 三叶草╮

处理示例:

        清洗成 ->     

Code:

import pandas as pd

# 读取Excel,跳过前面两行空行
studf = pd.read_excel(r'student_excel.xlsx', skiprows=2)
print(studf)
# 删除掉全部是空值的列
studf.dropna(axis='columns', how='all', inplace=True)
# 删除掉全部是空值的行
studf.dropna(axis='index', how='all', inplace=True)
# 将分数列为空的单元格填充为0
studf = studf.fillna({'分数': 0})
# 将姓名的缺失值进行前向填充
studf.loc[:, '姓名'] = studf['姓名'].ffill()
print(studf)
# 保存到新的Excel中 不保存index列
studf.to_excel(r'student_excel_clean.xlsx', index=False)

df.sort_values(by=['aqiLevel', 'bWendu'], ascending=[True, False], inplace=True)

# 将eg 2025-02-01 改为 提取到月份,且不要横线 如202502
df['date'] = df['date'].str.replace('-', '').str.slice(0, 6)
# 使用正则表达式处理 eg 将2025年01月02日中的年月日去掉,得到20250102
df['date'] = df['date'].str.replace(r'[年月日]', '', regex=True)

 

          

Pandas Index :

import timeit
import pandas as pd

file = r'ratings.csv'
df = pd.read_csv(file)
# drop=False,让索引列保留在数据集中
df.set_index('userId', inplace=True, drop=False)
# 使用索引查询userId=500的前5个行   效率更高
print(df.loc[500].head(5))
# 使用数据列的userId=500查询前5个行
print(df.loc[df['userId'] == 500].head(5))
# 判断索引是否单调递增
print(df.index.is_monotonic_increasing)
# 判断索引是否唯一
print(df.index.is_unique)

def my_function():
    # 这里放置你要测试的代码
    return df.loc[df['userId'] == 500].head(5)

# 使用 timeit 测试函数的执行时间
execution_time = timeit.timeit(my_function, number=1000)
print(f"执行时间: {execution_time} 秒")

# 使用Index实现数据集的自动对齐
s1 = pd.Series([1, 2, 3], index=list('abc'))
s2 = pd.Series([4, 5, 6], index=list('bcd'))
print(s1 + s2)
# 使用 add 方法并设置 fill_value 参数
result = s1.add(s2, fill_value=0)
print(result)

 Pandas Merge:

# 默认按行连接
result = pd.concat([df1, df2])
# 其余参数 axis 按行或按列对其,join='inner' 按交集连接,join='outer' 按并集连接,ignore_index=True 重新编号
result = pd.concat([df1, df2], axis=0, join='inner', ignore_index=True)
df3 = df1._append(df2)

Pandas Group By