python - 数据框附加日期时间数据并写入 .wac 文件
问题描述
我是 python 新手,在过去的几天里,我自学了如何使用 pandas 对存储在 txt、xls、asc 文件中的数据打开和执行操作,但是在使用数据帧进行操作时我仍然感到困惑。
我有一个格式正确的 .wac 文件(它必须随后用作软件的输入文件),但包含部分错误的值,以及一个包含正确值的 .xlsx 文件。
我已使用此代码将数据传输到两个数据帧(我使用skiprows跳过两个文件中的字符串数据):
data_format = pd.read_csv('Example.wac', skiprows=11, delim_whitespace=True, names=["Date", "Hour", "Temp gap North [C]", "RH %"])
data_WUFI =pd.read_excel('Temperature_RH_North.xlsx', skiprows=1, header=None, dtype=float, names=["Hour", "Temp gap [C]", "RH %"])
现在我需要对数据框进行以下修改,但我不知道从哪里开始,我希望我来对了地方寻求帮助。对于data_format:
- the column 'Date' is in the format *2018-01-01* and runs to *2019-12-31*. Being obviously a date, it stays the same for 24 positions and then it increases by 1 day. I need to add rows to that column up to *2027-12-31* (without leap years)
- the column 'Hour' is in the format *01:00*. Values run from *01:00* to *24:00*. I need to add rows so that every 24 hours the date in the first column increases by one day, then the hour numbering restarts at *01:00*
- The column 'RH %' contains the same value in all rows, i.e. 0.5
我添加了data_format的快照以使其更清晰:
一旦创建了新的数据框,例如data_format_NEW ,我可以用data_WUFI中的正确值(已经是正确的大小)替换“Temp gap North [C]”中的值:
data_format_NEW['Temp gap North [C]'] = data_WUFI['Temp gap [C]']
那时,我将 data_format_NEW 写入.wac文件:
data_format_NEW.to_csv('Example_NEW.wac', index=False, delim_whitespace=True)
但前 12 行必须包含字符串值,如图所示:
我不确定我的计划是否正确,但我希望我能够解释清楚自己
解决方案
推荐阅读
- docker - 将 .net core v2.1.13 升级到 v2.1.16 后,docker 上的 IdentityServer4 在 chrome 中不起作用
- keycloak - 如何使用 curl 增加 keycload 承载访问令牌时间?
- css - 在 UL 之后如何定义底部边距?
- node.js - 如何在带有自定义配置界面的打字稿中使用 node-config?
- markdown - 将多个章节拼接在一起,每个章节都有一个 % 标题
- c# - C#:为什么字符串和列表不支持序列化?
- reactjs - 在 componentDidMount 中模拟 API 调用方法
- scala - Flink AssignerWithPeriodicWatermarks getCurrentWatermark 永远不会被调用
- angular - 如何在Angular中显示文本区域内的当前字符数?
- azure-durable-functions - 使用持久实体是存储工作流结果的好方法吗?