【发布时间】:2019-10-15 05:53:04
【问题描述】:
我试图找出时间序列中的空白(间隔 30 分钟)并用 NaN 填充它们。
我指的是这篇文章中的说明,但事实证明代码在我的情况下表现不佳。 Find gaps in pandas time series dataframe sampled at 1 minute intervals and fill the gaps with new rows
import pandas as pd
from datetime import datetime
df=pd.read_csv('example1.csv')
df.head(5)
Date & Time KW
0 8/27/2019 23:30 0.016
1 8/27/2019 23:00 0
2 8/27/2019 22:30 0.016
3 8/27/2019 22:00 0.016
4 8/27/2019 21:30 0
df['Date & Time'] = pd.to_datetime(df['Date & Time'], format='%m/%d/%Y %H:%M')
df=df.set_index('Date & Time').asfreq('30M')
df.head()
KW
Date & Time
如您所见,输出为空白,我应该看到值。 我不确定我做错了什么。
【问题讨论】:
标签: python python-3.x pandas