timedelta

How to convert string value like "4w 2d.." to timedelta?

How to convert string value like "4w 2d.." to timedelta? Question: I have incoming string data in format like "4w 2d 5h" (weeks(w), days(d), hours(h), minutes(m)), some it can have different number of parameters (from 1 to 4, e.g "1w", "2w 5h", "3w 1d 5h 3m", etc). I need to convert it to timedelta (datetime) …

Total answers: 1

Python Datetime conversion for excel dataframe

Python Datetime conversion for excel dataframe Question: Hello, I am trying to extract date and time column from my excel data. I am getting column as DataFrame with float values, after using pandas.to_datetime I am getting date with different date than actual date from excel. for example, in excel starting date is 01.01.1901 00:00:00 but …

Total answers: 1

Converting x-axis label from datetime to timedelta

Converting x-axis label from datetime to timedelta Question: I’m trying to plot some time series data which spans across a number of days. I have some sample code: vals = np.random.uniform(low=5.5, high=5.6, size=(100,)) datetime = pd.date_range(start=’2022-03-10′, end=’2022-03-15′, periods=100) time0 = datetime[0] timedelta = datetime-time0 day = timedelta.astype(‘timedelta64[D]’) fig, ax = plt.subplots() ax.plot(timedelta,vals) ax.plot(timedelta,vals) which results …

Total answers: 1

Convert mm:ss string to hh:mm:ss time format in Python

Convert mm:ss string to hh:mm:ss time format in Python Question: Screenshot of dataframe I am working on I want to convert the values in df[‘Chip Time’] column which are string obj to timedelta64. Have tried this….> df2[‘Chip Time’] = pd.to_timedelta(df2[‘Chip Time’]) BUT GETS Error message …> ValueError: expected hh:mm:ss format Asked By: Chukwunonso Jide || …

Total answers: 2

Python: Pandas Timedelta for one month

Python: Pandas Timedelta for one month Question: Is there a way to do a Timedelta for one month? Applying pd.Timedelta(‘1M’) yields Timedelta(‘0 days 00:01:00’). Is there a code word for month? Asked By: MathMan 99 || Source Answers: Timedelta is for absolute offsets. A month "offset", by definition, might have different lengths depending on the …

Total answers: 1

Python timedelta time difference from the given varied time of every day

Python timedelta time difference from the given varied time of every day Question: I have the these two following pandas dataframe : df1 = {‘Date’ : [’07-10-2019′, ’07-10-2019′, ’07-10-2019′, ’08-10-2019′, ’08-10-2019′, ’08-10-2019′]} df1 = {‘Time’ :[’07-10-2019 10:47:00′, ’07-10-2019 10:52:00′, ’07-10-2019 10:59:00′, ’08-10-2019 10:47:00′, ’08-10-2019 10:52:00′, ’08-10-2019 10:59:00′, ]} and I am trying to create d[‘Time …

Total answers: 1

Is there a bug in Python 3.8 datetime with DST transitions?

Is there a bug in Python 3.8 datetime with DST transitions? Question: I’m trying to convert a timezone-aware datetime in Europe/Sofia to the start of the day in Europe/Sofia, but returning the datetime in UTC. Doing this, I encountered a strange problem: #!/usr/bin/env python import sys import pytz from datetime import datetime, timedelta def main(): …

Total answers: 1

Python datetime only returning negative numbers?

Python datetime only returning negative numbers? Question: I have the following code: commit_date = get_last_commit_date() # returns datetime obj: 2022-08-25 13:32:12 pr_date = datetime.fromisoformat(ISO_CODE) # returns 2022-08-24 19:15:07 Notice how commit_date is Aug. 25 and pr_date is Aug. 24. I want to find the difference in days which should be 1 day. Now doing print((pr_date …

Total answers: 1

window timedelta not recording all records

window timedelta not recording all records Question: This is in relations to a previous post from here: I am trying to build a set of analytics that would catch students sharing answers. I need to have the format so that I can create some nice plots that would show the results. Not only that but …

Total answers: 2

check if model was recently updated fails trying to use timedelta

check if model was recently updated fails trying to use timedelta Question: I have the following model that saves a datetime on save: class StockInfo(models.Model): ticker = models.CharField(max_length=100) current_price = models.FloatField() name = models.CharField(max_length=255) summary = models.TextField() sector = models.CharField(max_length=100) dividends = models.ArrayField(model_container=Dividend) last_updated_time = models.DateTimeField(null=True) objects = models.DjongoManager() # https://stackoverflow.com/questions/9953427/django-custom-save-model def save(self, *args, **kwargs): …

Total answers: 1