Home > Enterprise >  selecting rows in dataframe using datetime.datetime
selecting rows in dataframe using datetime.datetime

Time:05-13

Python is new for me.

I want to select a range of rows by using the datetime which is also the index.

I am not sure if having the datetime as the index is a problem or not.

my dataframe looks like this:

                     gradient
date                         
2022-04-15 10:00:00  0.013714
2022-04-15 10:20:00  0.140792
2022-04-15 10:40:00  0.148240
2022-04-15 11:00:00  0.016510
2022-04-15 11:20:00  0.018219
                      ...
2022-05-02 15:40:00  0.191208
2022-05-02 16:00:00  0.016198
2022-05-02 16:20:00  0.043312
2022-05-02 16:40:00  0.500573
2022-05-02 17:00:00  0.955833

And I have made variables which contain the start and end date of the rows I want to select. This looks like this:

A_start_646 = datetime.datetime(2022,4,27, 11,0,0)
S_start_646 = datetime.datetime(2022,4,28, 3,0,0)
D_start_646 = datetime.datetime(2022,5,2,   15,25,0)
D_end_646 = datetime.datetime(2022,5, 2,   15,50,0)

So I would like to make a new dataframe. I saw some examples on the internet, but they use another way of expressing the date.

Does somewan know a solution?

CodePudding user response:

I feel kind of stupid and smart at the same time now. This because I have already answered my own question, my apologies

So this is the answer:

new_df = data_646_mean[A_start_646 : S_start_646]
  • Related