Python Forum
Learning indexing with python, pick dates
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learning indexing with python, pick dates
#1
Hi all,
I have two data frames both contain time indexes with the same time period.
I want to pick start and end periods from the first data frame

start=small_df.index[1]
Output:
Out[894]: Timestamp('2019-02-08 07:53:33.360000')
end=small_df.index[10]
Output:
Out[895]: Timestamp('2019-02-08 07:54:00.149000')
and then I want to pick the numeric indexes from a second data frame where these time stamps fall in.



Can you think of an elegant way to do that?
Thanks a lot
Alex
Reply
#2
I think, quite elegant would be a two stage approach, e.g.
cond = (df2.index > start) & (df2.index < end)
df2.reset_index()[cond].index     # or concat `.tolist()` statement,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pick a line in a plot with matplotlib Romain 3 5,542 Feb-28-2023, 11:56 AM
Last Post: get2sid
  python pandas: diff between 2 dates in a groupby bluedragon 0 3,250 Mar-25-2020, 04:18 PM
Last Post: bluedragon
  python array/cell/indexing python 1 2,761 Feb-08-2018, 11:18 AM
Last Post: DeaD_EyE
  Extract data between two dates from a .csv file using Python 2.7 sujai_banerji 1 10,307 Nov-15-2017, 09:48 PM
Last Post: snippsat
  How to pick random entries of stock prices? Alberto 1 3,286 Jul-16-2017, 09:51 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020