当前位置: 首页 > news >正文

胶州网站建设哪里有网站验收标准

胶州网站建设哪里有,网站验收标准,哪个网站容易做二级域名,中山免费建站🤟致敬读者 🟩感谢阅读🟦笑口常开🟪生日快乐⬛早点睡觉 📘博主相关 🟧博主信息🟨博客首页🟫专栏推荐🟥活动信息 文章目录Python Pandas读取Excel表格中数据并根据时间…

🤟致敬读者

  • 🟩感谢阅读🟦笑口常开🟪生日快乐⬛早点睡觉

📘博主相关

  • 🟧博主信息🟨博客首页🟫专栏推荐🟥活动信息

文章目录

  • Python Pandas读取Excel表格中数据并根据时间字段筛选数据
    • 1. 需求描述
    • 2. 读取excel表格
    • 3. 筛选最新时间
    • 4. 筛选具体月份数据
    • 5.输出结果
    • 6. 完整代码


📃文章前言

  • 🔷文章均为学习工作中整理的笔记。
  • 🔶如有错误请指正,共同学习进步。

Python Pandas读取Excel表格中数据并根据时间字段筛选数据

1. 需求描述

现在有一个excel表格,其中包含设备字段device_id、最后使用时间字段end_time以及其他字段若干
需要将表格中的每个设备对应的最新的使用时间筛选出来,并在结果中根据最新时间筛选出4月和5月
对应的设备号列表

2. 读取excel表格

import pandas as pd# 读取 Excel 文件
file_path = r"C:\Users\Downloads\file_record.xlsx"  # 替换为你的文件路径
df = pd.read_excel(file_path)
# 显示前几行数据
# print(df.head())
# print(df)

在这里插入图片描述

3. 筛选最新时间

先根据时间重置DataFrame对象

# Assuming 'df' is your DataFrame and 'end_time' is initially in string format
df['end_time'] = pd.to_datetime(df['end_time'])  # Convert to datetime if necessary

然后根据设备号分组,再取end_time中最新即最大时间值,并重置索引

# Group by 'device_id' and find the max (latest) 'end_time' for each group
latest_end_times = df.groupby('device_id')['end_time'].max().reset_index()

4. 筛选具体月份数据

在上面的最新时间中筛选出4月和5月的设备列表

# Filter the 'latest_end_times' DataFrame to only include devices with 'end_time' in April or May
filtered_devices = latest_end_times[(latest_end_times['end_time'].dt.month == 4) | (latest_end_times['end_time'].dt.month == 5)
]

5.输出结果

遍历结果中设备和时间信息

for index, row in filtered_devices.iterrows():device_id = row['device_id']latest_end_time = row['end_time']print(f"Device ID: {device_id}, Latest End Time: {latest_end_time}")# 'filtered_devices' now contains the device information for which the latest 'end_time' is in April or May

在这里插入图片描述

6. 完整代码

完整代码如下

import pandas as pd# 读取 Excel 文件
file_path = r"C:\Users\Downloads\file_record.xlsx"  # 替换为你的文件路径
df = pd.read_excel(file_path)# 显示前几行数据
# print(df.head())
# print(df)# Assuming 'df' is your DataFrame and 'end_time' is initially in string format
df['end_time'] = pd.to_datetime(df['end_time'])  # Convert to datetime if necessary
# print(df.head())# Group by 'device_id' and find the max (latest) 'end_time' for each group
latest_end_times = df.groupby('device_id')['end_time'].max().reset_index()
# print(df)# Filter the 'latest_end_times' DataFrame to only include devices with 'end_time' in April or May
filtered_devices = latest_end_times[(latest_end_times['end_time'].dt.month == 4) | (latest_end_times['end_time'].dt.month == 5)
]for index, row in filtered_devices.iterrows():device_id = row['device_id']latest_end_time = row['end_time']print(f"Device ID: {device_id}, Latest End Time: {latest_end_time}")# 'filtered_devices' now contains the device information for which the latest 'end_time' is in April or May

📜文末寄语

  • 🟠关注我,获取更多内容。
  • 🟡技术动态、实战教程、问题解决方案等内容持续更新中。
  • 🟢《全栈知识库》技术交流和分享社区,集结全栈各领域开发者,期待你的加入。
  • 🔵​加入开发者的《专属社群》,分享交流,技术之路不再孤独,一起变强。
  • 🟣点击下方名片获取更多内容🍭🍭🍭👇

http://www.dtcms.com/a/575485.html

相关文章:

  • 仓储网站建设在那些网站上做企业宣传好
  • 网站竞价怎么做即时设计广告
  • 齐齐哈尔企业网站排名优化郑州校园兼职网站建设
  • 企业网站 域名注册wordpress 分享后阅读
  • 遵义制作公司网站的公司做网站一天忙吗
  • 深圳网站域名注册猎头网站 做猎头的流程
  • n加1网站建设工商网查询营业执照
  • dede 电商网站高权重网站收录问题
  • 关键词解释:LN(Layer Normalization,层归一化)和 BN(Batch Normalization,批归一化)
  • 网站排名有什么用wordpress标题添加连载中
  • 营销策划培训seo线下培训机构
  • 基于Optuna 贝叶斯优化超参数调优之使用TPE创建研究对象
  • 知识就是力量——温湿度传感器选型2.0
  • 做音乐网站要注意什么电脑经销部开具网站建设费
  • 福州网站建设方案服务青岛建设集团有限公司
  • <RT1176系列15>clock_config代码分析
  • 台州关键词首页优化东莞网站seo优化
  • 密云上海网站建设综合搜索引擎
  • 中国建设银行企业网站个人网站如何进行网络推广
  • 建设网站怎么克隆建设网站与服务器
  • 网站空间要备案吗东莞市网站建设分站品牌
  • 云南网站建设网站运营中英文切换的网站怎么做的
  • 网站都是怎么做的辽宁建设工程信息网上传标书时显示初始化签名证书选择模式失败
  • 长沙企业建站按效果付费wordpress随机文章
  • 可以写代码的网站有哪些问题怎么可以创建网站
  • 门户网站建设哪家便宜建设工程报建备案网站
  • [RE2] docs | FullMatch PartialMatch | 自动匹配
  • wordpress评测网站做黄金的分析师网站
  • 信阳市网站建设公司东莞企业推广网站
  • 怎样自己建个人网站wordpress文章自适应图片大小