Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.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索引大于x_Python_Pandas_Dataframe - Fatal编程技术网

在多天的数据框架中,日期列的Python索引大于x

在多天的数据框架中,日期列的Python索引大于x,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个由许多天的数据组成的一列大数据框。某一天,我想找到那些大于x的值的日期时间索引。另外,我想知道当天的整数指数 df = POA0 datetime 2019-07-05 07:53:53 81.605703 2019-07-05 08:33:57 120.913055 2019-07-05 09:13:25 290.052470 2019-07-06 09:53:29 515.10

我有一个由许多天的数据组成的一列大数据框。某一天,我想找到那些大于x的值的日期时间索引。另外,我想知道当天的整数指数

df =                           POA0
datetime                       
2019-07-05 07:53:53   81.605703
2019-07-05 08:33:57  120.913055
2019-07-05 09:13:25  290.052470
2019-07-06 09:53:29  515.109924
2019-07-06 10:33:27  644.393595
2019-07-06 11:13:28  745.543610
2019-07-06 11:53:25  831.441294
2019-07-07 12:33:23  889.082789
2019-07-07 13:53:23  906.169942
2019-07-07 14:33:25  874.149780
2019-07-08 15:13:25  809.388652
2019-07-08 15:53:22  439.487053
2019-07-08 16:33:28  246.558506
2019-07-08 17:13:49  193.730774
2019-07-08 17:53:57  145.934008
我想找到那些大于700的值的索引。我的代码是:

day = '2019-07-06'
bool_idx = df['POA0'].loc[day]>700
time_idx = df[bool_idx].index

print(time_idx)
    [2019-07-05 07:53:53
    2019-07-05 08:33:57
    2019-07-05 09:13:25
    2019-07-06 09:53:29
    2019-07-06 10:33:27
    2019-07-06 11:13:28
    2019-07-06 11:53:25
    2019-07-07 12:33:23
    2019-07-07 13:53:23
    2019-07-07 14:33:25
    2019-07-08 15:13:25
    2019-07-08 15:53:22
    2019-07-08 16:33:28
    2019-07-08 17:13:49
    2019-07-08 17:53:57]
上面的输出不是我想要的。此外,为了获得上述输出,我只想使用一行代码,但我使用了两行代码。可以用一行来做吗?在这两者之间,我只想输出当天的索引,如下所示

print(time_idx)
    [2019-07-06 11:13:28
    2019-07-06 11:53:25]
另外,我想知道上面输出的整数索引为

print(int_idx)
   [2,3]
尝试:

输出:

DatetimeIndex(['2019-07-06 11:13:28', '2019-07-06 11:53:25'], dtype='datetime64[ns]', name='datetime', freq=None)
array([2, 3], dtype=int64)
对于整数索引:

day = '2019-07-06'
limit = 700

df.loc[day].index.get_indexer(df.loc[day].query('POA0 > @limit').index)
输出:

DatetimeIndex(['2019-07-06 11:13:28', '2019-07-06 11:53:25'], dtype='datetime64[ns]', name='datetime', freq=None)
array([2, 3], dtype=int64)
根据使用Python 3.6+的注释使用f-string: 作为一个列表

day = '2019-07-06'
limit = 700
col_name = ['POA0']

df.loc[day].query(f'{col_name[0]} > {limit}').index.tolist()

非常感谢。它按我的要求工作。我将列名(我的问题中未显示)存储在列表中,作为
col\u nam=['POA0']
。我如何在上面的代码中使用它?我根据您的更新尝试了
df.loc[day].query(f'{col_name}>{limit}').index.tolist()
获得以下输出:
TypeError:data type not understanding
添加了列表选项。试试看。