Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在特定时间序列中插入缺少的行_Python_Pandas_Timestamp - Fatal编程技术网

Python 在特定时间序列中插入缺少的行

Python 在特定时间序列中插入缺少的行,python,pandas,timestamp,Python,Pandas,Timestamp,我有一个特定的时间序列数据集,如下所示 0 2018-01-01 00:00:00+00:00 ... 1 2018-01-01 00:10:00+00:00 ... 2 2018-01-01 00:20:00+00:00 ... 3 2018-01-01 00:30:00+00:00

我有一个特定的时间序列数据集,如下所示

0     2018-01-01 00:00:00+00:00  ...                             
1     2018-01-01 00:10:00+00:00  ...                              
2     2018-01-01 00:20:00+00:00  ...                             
3     2018-01-01 00:30:00+00:00  ...                             
4     2018-01-01 00:50:00+00:00  ...                            
5     2018-01-01 01:00:00+00:00  ...                              
6     2018-01-01 01:20:00+00:00  ...                             
7     2018-01-01 01:40:00+00:00  ...
.
.
.
但是,数据集中缺少一些行。 我搜索了如何为这个特定的数据集插入行,但没有找到任何有用的帮助。在这个数据集中,我们必须添加每10分钟有一个条目的行,其他列应该有Nan值


有什么想法吗?

首先创建
DatetimeIndex
并调用:


首先创建
DatetimeIndex
并调用:


嗨,欢迎来到苏。如果你能展示一些你尝试的代码,那就太好了。嗨,欢迎来到SO。如果你能展示一些你尝试的代码,那就太好了?
print (df)
                    date_col  value
0  2018-01-01 00:00:00+00:00      4
1  2018-01-01 00:10:00+00:00      9
2  2018-01-01 00:20:00+00:00      1
3  2018-01-01 00:30:00+00:00      6
4  2018-01-01 00:50:00+00:00      3
5  2018-01-01 01:00:00+00:00      4
6  2018-01-01 01:20:00+00:00      5
7  2018-01-01 01:40:00+00:00      0

#if necessary
df['date_col'] = pd.to_datetime(df['date_col'])

df = df.set_index('date_col').asfreq('10Min')
print (df)
                           value
date_col                        
2018-01-01 00:00:00+00:00    4.0
2018-01-01 00:10:00+00:00    9.0
2018-01-01 00:20:00+00:00    1.0
2018-01-01 00:30:00+00:00    6.0
2018-01-01 00:40:00+00:00    NaN
2018-01-01 00:50:00+00:00    3.0
2018-01-01 01:00:00+00:00    4.0
2018-01-01 01:10:00+00:00    NaN
2018-01-01 01:20:00+00:00    5.0
2018-01-01 01:30:00+00:00    NaN
2018-01-01 01:40:00+00:00    0.0