简体   繁体   English

在行中插入缺失的日期

[英]Inserting Missing dates in rows

在此处输入图像描述

I have this data frame where weather data is available.我有这个数据框,其中天气数据可用。

Problem - My problem is when I try to add missing dates with the code below:-问题-我的问题是当我尝试使用以下代码添加缺少的日期时:-

dt = pd.date_range("01-01-2021","01-11-2021")

idx = pd.DatetimeIndex(dt)

new_df9 = df_missing_values.reindex(idx)

After adding the dates - 2021-02-01, all my data in temperature, windspeed and event columns transformed to NaN values.添加日期 - 2021-02-01 后,我在温度、风速和事件列中的所有数据都转换为 NaN 值。 As you can see in the image below:-如下图所示:-

在此处输入图像描述

Please help me fix this issue.请帮我解决这个问题。

Apparently, your data is identified as monthly data.显然,您的数据被标识为月度数据。 For example, the second row is the first of April of 2021, that is why when you reindex until the 11th of January the rest of the data is gone.例如,第二行是 2021 年 4 月的第一行,这就是为什么当您重新索引到 1 月 11 日时,数据的 rest 消失了。

You might need to correct the index first to 2021-01-04 instead of 2021-04-01 if the data corresponds to the 4th of January instead of the 1st of April如果数据对应于 1 月 4 日而不是 4 月 1 日,您可能需要先将索引更正为2021-01-04而不是2021-04-01

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM