因为wps的自带格式没有"XXXX年",所以可以用python做
import pandas as pd
# 读取 Excel 文件
df = pd.read_excel("example.xlsx")
# 将 "日期" 列转换为 datetime 类型
df["日期"] = pd.to_datetime(df["日期"])
# 提取年份并覆盖原来的 "日期" 列
df["日期"] = df["日期"].dt.year
# 将处理后的数据保存到新文件
df.to_excel("example_year_only.xlsx", index=False)
首先,使用 Pandas 的 read_excel()
函数读取 Excel 文件,然后使用 to_datetime()
函数将 "日期" 列转换为 Pandas 中的 datetime 类型。随后,使用 dt.year
属性提取年份并覆盖原来的 "日期" 列。最后,使用 to_excel()
函数将处理后的数据保存到新文件中。
需要注意的是,这个代码假设当前 Excel 文件中的 "日期" 列格式为 "2001/6/12"。如果您的日期格式不同,请在代码中相应地调整日期解析方式。