Category : timedelta

If I make up some time series data: import pandas as pd import numpy as np from numpy.random import seed # seed random number generator seed(1) time = pd.date_range(‘6/28/2021′, periods=100, freq=’1min’) df = pd.DataFrame(np.random.randint(100, size=100), index=time,columns=[‘data’]) df.plot(figsize=(25,8)) This will plot: And then filter the data for when data is above 50: df = df.loc[df[‘data’] > ..

Read more

I have a simple method to add hours to a time string. Here is my code: def add_hours(time_str: str, hours: float) -> datetime: # Convert flot time to timedelta added_hour = timedelta(hours=hours) # str to datetime date_time = datetime.strptime(time_str, "%H:%M") return date_time + added_hour print(add_hours("21:52", hours= 2.5)) 1900-01-02 00:22:00 I simply convert the string time ..

Read more

I have a Dataframe with a datetimeindex and I need to create a column that contains the difference in time between the rows of the datetimeindex expressed in hours. This is what I have: Datetime Numbers 2020-11-27 08:30:00 1 2020-11-27 13:00:00 2 2020-11-27 15:15:00 3 2020-11-27 20:45:00 4 2020-11-28 08:45:00 5 2020-11-28 10:45:00 6 2020-12-01 ..

Read more