Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
119 views
in Technique[技术] by (71.8m points)

python - Selecting Data between Specific hours in a pandas dataframe

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.   ............
 6.   ............
 7. 2013-10-10 09:00:05
 8. 2013-10-10 09:05:00 
 9. 2013-10-10 10:00:00

I want the data lying in between hours 9 and 10 ...if anyone has worked on something like this ,it would be really helpful.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
 In [7]: index = date_range('20131009 08:30','20131010 10:05',freq='5T')

In [8]: df = DataFrame(randn(len(index),2),columns=list('AB'),index=index)

In [9]: df
Out[9]: 
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 308 entries, 2013-10-09 08:30:00 to 2013-10-10 10:05:00
Freq: 5T
Data columns (total 2 columns):
A    308  non-null values
B    308  non-null values
dtypes: float64(2)

In [10]: df.between_time('9:00','10:00')
Out[10]: 
                            A         B
2013-10-09 09:00:00 -0.664639  1.597453
2013-10-09 09:05:00  1.197290 -0.500621
2013-10-09 09:10:00  1.470186 -0.963553
2013-10-09 09:15:00  0.181314 -0.242415
2013-10-09 09:20:00  0.969427 -1.156609
2013-10-09 09:25:00  0.261473  0.413926
2013-10-09 09:30:00 -0.003698  0.054953
2013-10-09 09:35:00  0.418147 -0.417291
2013-10-09 09:40:00  0.413565 -1.096234
2013-10-09 09:45:00  0.460293  1.200277
2013-10-09 09:50:00 -0.702444 -0.041597
2013-10-09 09:55:00  0.548385 -0.832382
2013-10-09 10:00:00 -0.526582  0.758378
2013-10-10 09:00:00  0.926738  0.178204
2013-10-10 09:05:00 -1.178534  0.184205
2013-10-10 09:10:00  1.408258  0.948526
2013-10-10 09:15:00  0.523318  0.327390
2013-10-10 09:20:00 -0.193174  0.863294
2013-10-10 09:25:00  1.355610 -2.160864
2013-10-10 09:30:00  1.930622  0.174683
2013-10-10 09:35:00  0.273551  0.870682
2013-10-10 09:40:00  0.974756 -0.327763
2013-10-10 09:45:00  1.808285  0.080267
2013-10-10 09:50:00  0.842119  0.368689
2013-10-10 09:55:00  1.065585  0.802003
2013-10-10 10:00:00 -0.324894  0.781885

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...