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

推荐订阅源

cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
小众软件
小众软件
博客园_首页
博客园 - 聂微东
V
V2EX
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
SegmentFault 最新的问题
J
Java Code Geeks
Last Week in AI
Last Week in AI
The Cloudflare Blog
月光博客
月光博客
雷峰网
雷峰网
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
博客园 - Franky
腾讯CDC
Jina AI
Jina AI
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
量子位
爱范儿
爱范儿
美团技术团队
T
Tailwind CSS Blog
博客园 - 【当耐特】
D
Docker
IT之家
IT之家
V
Visual Studio Blog
P
Proofpoint News Feed
L
LangChain Blog
Engineering at Meta
Engineering at Meta
C
Check Point Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
Recorded Future
Recorded Future

博客园 - 三叶草╮

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