python 时间错位对齐
我的excel时间列想让过去7点内所有的时间值对应8,8点所有的值对应9这样

# -*- coding:utf-8 -*- """ @author: suyue @file: lianxi.py @time: 2025/09/19 @desc:时间对齐 """ import pandas as pd # 读取Excel文件 df = pd.read_excel('/数据汇总.xlsx') # 处理时间对齐 df['时间'] = df['时间'].astype(str).str.zfill(4) df['对齐时间'] = (df['时间'].str[:2].astype(int) + 1) % 24 # 显示结果 print(df.head(10)) # 保存到新文件 df.to_excel('/时间对齐.xlsx', index=False) print("处理完成,结果已保存到 output.xlsx")


浙公网安备 33010602011771号