Selecting Data between Specific hours in a pandas dataframe

后端 未结 3 1837
灰色年华
灰色年华 2020-12-03 14:16

My Pandas Dataframe frame looks something like this

 1. 2013-10-09 09:00:05
 2. 2013-10-09 09:05:00
 3. 2013-10-09 10:00:00
 4.  ............
 5.   .........         


        
3条回答
  •  [愿得一人]
    2020-12-03 15:09

    Make a new column for the time after splitting your original column . Use the below code to split your time for hours, minutes, and seconds:-

    df[['h','m','s']] = df['Time'].astype(str).str.split(':', expand=True).astype(int)
    

    Once you are done with that, you have to select the data by filtering it out:-

    df9to10 =df[df['h'].between(9, 10, inclusive=True)]
    

    And, it's dynamic, if you want to take another period between apart from 9 and 10.

提交回复
热议问题