处理示例:

        清洗成 ->     

 

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

       

  

 

posted @ 2025-03-04 15:26 三叶草╮ 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 1.官网 https://pandas.pydata.org/docs/user_guide/10min.html 01.读写Excel: import pandas as pd # 读取Excel帮助Link :https://pandas.pydata.org/docs/user_guide/i 阅读全文
posted @ 2025-02-17 16:11 三叶草╮ 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 1.官网 https://playwright.nodejs.cn/docs/api/class-playwright 2.Playwright for Python:https://playwright.bootcss.com/python/docs/intro 3.入门笔记:https://ww 阅读全文
posted @ 2024-12-12 16:06 三叶草╮ 阅读(26) 评论(0) 推荐(0) 编辑
摘要: 转自:https://blog.51cto.com/u_15493782/12582000 阅读全文
posted @ 2024-11-25 14:15 三叶草╮ 阅读(4) 评论(0) 推荐(0) 编辑
摘要: HandyControl Panuon.WPF.UI AduSkin Layui-WPF HandyControl HandyControl是一套WPF控件库,它几乎重写了所有原生样式,同时包含80余款自定义控件。使用HandyControl你可以轻松地创建一个美观的WPF应用程序,从而大大提高开发 阅读全文
posted @ 2024-11-07 15:59 三叶草╮ 阅读(382) 评论(0) 推荐(0) 编辑
摘要: 1 ChromeOptions option = new ChromeOptions(); 2 option.AddArgument("disable-extensions"); 3 option.AddArgument("--start-maximized"); 4 IWebDriver sele 阅读全文
posted @ 2019-01-03 16:37 三叶草╮ 阅读(408) 评论(0) 推荐(0) 编辑
摘要: 在这里我们将将打造一个UserControl(用户控件)来逐步讲解如何在WPF中自定义控件,并将WPF的一些新特性引入到自定义控件中来.我们制作了一个带语音报时功能的钟表控件, 效果如下:在VS中右键单击你的项目,点击"添加新项目",在出现的选择列表中选择"UserControl",VS会自动为你生 阅读全文
posted @ 2018-11-01 11:03 三叶草╮ 阅读(430) 评论(0) 推荐(0) 编辑
摘要: WPF升级了CLR的属性系统,加入了依赖属性和附加属性。依赖属性的使用有很多好处,其中有两点是我认为最为亮眼的: 1)节省内存的开销; 2)属性值可以通过Binding依赖于其它对象上,这就使得我的数据源一变动全部依赖于此数据源的依赖属性全部进行更新。 第二点开发过WPF或者SilverLight应 阅读全文
posted @ 2018-10-18 17:36 三叶草╮ 阅读(565) 评论(0) 推荐(0) 编辑
摘要: 有的时候,我们需要一个支持页面跳转的UI,例如文件浏览器,开始向导等。对于这样的界面,简单的可以使用ContentControl + ContentTemplateSelector的方式来实现,但是有的时候我们会需要一些更加高级的跳转功能,如前进,回退等。这个时候,用这个方式就稍微有点力不从心了,此 阅读全文
posted @ 2018-10-09 13:39 三叶草╮ 阅读(674) 评论(0) 推荐(0) 编辑
摘要: //1.添加引用-〉com-〉microsoft excel 11.0 //2.若出现错误:命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”(是缺少程序集引用吗?) //解决方法:先删除引用中的Excel,然后找到文件Microsoft.Office.Interop.Excel.dll,手动添加该文件的引用 using System; using Sy... 阅读全文
posted @ 2018-03-08 23:08 三叶草╮ 阅读(4369) 评论(0) 推荐(1) 编辑
点击右上角即可分享
微信分享提示