pandas, python - how to select specific times in timeseries

后端 未结 4 1263
予麋鹿
予麋鹿 2020-12-12 17:58

I worked now for quite some time using python and pandas for analysing a set of hourly data and find it quite nice (Coming from Matlab.)

Now I am kind of stuck. I cr

4条回答
  •  执念已碎
    2020-12-12 18:12

    Pandas DataFrame has a built-in function pandas.DataFrame.between_time

    df = pd.DataFrame(np.random.randn(1000, 2),
                      index=pd.date_range(start='2017-01-01', freq='10min', periods=1000))
    

    Create 2 data frames for each period of time:

    df1 = df.between_time(start_time='10:00', end_time='13:00') 
    df2 = df.between_time(start_time='20:00', end_time='23:00')
    

    Data frame you want is merged and sorted df1 and df2:

    pd.concat([df1, df2], axis=0).sort_index()
    

提交回复
热议问题