Home > Software engineering >  How can I increase Dataframe time by 5 minutes gap?
How can I increase Dataframe time by 5 minutes gap?

Time:11-13

I want to increase the time by 5 minutes gap.

I have two times:

time1 - "09:30:59"
time2 - "15:15:59"

time1 and time2 will be changing. it's not fixed.

I want output:

09:30:59
09:35:59
09:40:59
09:45:59
09:50:59
09:55:59
10:00:59
10:05:59
10:10:59
10:15:59
10:20:59
..
..
..
..
14:50:59
14:55:59
15:00:59
15:05:59
15:10:59
15:15:59

And I want this out in time format.

I don't understand how I can do this. I'm new to programming. Please help me to solve this.

CodePudding user response:

Use pd.date_range with pd.Series:

In [414]: s = pd.Series(pd.date_range("09:30:59", "15:15:59", freq="5min")).dt.time

In [415]: s
Out[415]: 
0     09:30:59
1     09:35:59
2     09:40:59
3     09:45:59
4     09:50:59
        ...   
65    14:55:59
66    15:00:59
67    15:05:59
68    15:10:59
69    15:15:59
Length: 70, dtype: object

CodePudding user response:

You can use pandas date_range. Like this:

date_range_df = pd.date_range(start='2013-10-28 9:30:59', end='2013-10-28 10:30:59', freq='300s')
for dt in date_range_df:
    print(dt)
  • Related