Python Pandas: drop rows of a timeserie based on time range

后端 未结 4 1346
我在风中等你
我在风中等你 2021-02-08 20:56

I have the following timeserie:

start = pd.to_datetime(\'2016-1-1\')
end = pd.to_datetime(\'2016-1-15\')
rng = pd.date_range(start, end, freq=\'2h\')
df = pd.Dat         


        
4条回答
  •  情歌与酒
    2021-02-08 21:31

    using query

    df.query('index < @start_remove or index > @end_remove')
    

    using loc

    df.loc[(df.index < start_remove) | (df.index > end_remove)]
    

    using date slicing

    This includes the end points

    pd.concat([df[:start_remove], df[end_remove:]])
    

    And without the end points

    pd.concat([df[:start_remove], df[end_remove:]]).drop([start_remove, end_remove])
    

提交回复
热议问题