Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.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 如何仅对DatetimeIndex进行排序?_Python_Pandas_Dataframe_Indexing_Datetimeindex - Fatal编程技术网

Python 如何仅对DatetimeIndex进行排序?

Python 如何仅对DatetimeIndex进行排序?,python,pandas,dataframe,indexing,datetimeindex,Python,Pandas,Dataframe,Indexing,Datetimeindex,我有一个像这样的DatetimeIndex DatetimeIndex(['2015-04-29 00:00:00', '2016-02-22 16:00:00', '2016-02-12 04:00:00', '2016-02-16 04:00:00', '2016-02-09 12:00:00', '2016-02-11 07:00:00', '2015-08-06 00:00:00', '2014-1

我有一个像这样的DatetimeIndex

DatetimeIndex(['2015-04-29 00:00:00', '2016-02-22 16:00:00',
               '2016-02-12 04:00:00', '2016-02-16 04:00:00',
               '2016-02-09 12:00:00', '2016-02-11 07:00:00',
               '2015-08-06 00:00:00', '2014-10-31 00:00:00',
               '2014-11-14 00:00:00', '2015-09-24 00:00:00',
               ...
               '2015-12-30 00:00:00', '2015-11-30 00:00:00',
               '2016-02-19 20:00:00', '2014-11-13 00:00:00',
               '2014-12-15 00:00:00', '2015-06-16 00:00:00',
               '2015-12-31 00:00:00', '2015-01-09 00:00:00',
               '2015-11-25 00:00:00', '2015-03-12 00:00:00'],
              dtype='datetime64[ns]', length=604, freq=None)
和一个(更长的)数据帧,如下所示:

Df: 
                          Val       
Time                                                          
2014-10-10 00:00:00       ...  
2014-10-13 00:00:00       ...
2014-10-14 00:00:00       ...  
2014-10-15 00:00:00       ...
2014-10-16 00:00:00       ...  
                      ...       ...  ...            ...            ...
2016-02-23 16:00:00       ...
2016-02-23 17:00:00       ...   
2016-02-23 18:00:00       ... 
2016-02-23 19:00:00       ...   
2016-02-23 20:00:00       ...

我怎样才能获得数据帧,其中只有位于这些索引上的数据帧行

如果可能,一些不匹配的值将用于:

或通过以下方式选择:

如果所有匹配的值都是可能的,则只需选择
loc
,即可简化答案,但如果至少有一个值不匹配,则在新版本的pandas中失败:

df2 = df.loc[idx]

Df.loc[您的日期列表]
df1 = df.loc[df.index.intersection(idx)]
df2 = df.loc[idx]