1,933 questions
0
votes
1
answer
75
views
Importing CSV after initially exporting datetime output (without using pandas)
I use the following to write CSV lines in a loop while running sensor instrumentation, and I want to read them back in for post-processing without pandas. I would like to use the imported data to ...
1
vote
1
answer
59
views
numpy.ndarray of seconds of a day to datetime format
I have a Python numpy.ndarray of seconds of the day with a bunch of decimal seconds:
import numpy as np
sec = [40389.66574375, 40390.12063928, 40391.32714992, 40392.64457077, 40393.48519607, 40394....
7
votes
2
answers
190
views
Why does `strftime("%Y")` not yield a 4-digit year for dates < 1000 AD in Python's datetime module on Linux?
I am puzzled by an inconsistency when calling .strftime() for dates which are pre-1000 AD, using Python's datetime module.
Take the following example:
import datetime
old_date = datetime.date(year=33, ...
2
votes
1
answer
73
views
Why datetime.datetime.strptime %Z code doesn’t produce an aware object?
A little example:
$ python
Python 3.13.2 (main, Feb 5 2025, 08:05:21) [GCC 14.2.1 20250128] on linux
Type "help", "copyright", "credits" or "license" for more ...
3
votes
1
answer
81
views
Python ValueError: ':' is a bad directive in format '%Y-%m-%d%X%:z'
I'm attempting to parse HTML time strings in Python:
from datetime import datetime
input = "2025-03-24T07:01:53+00:00"
output = datetime.strptime(input, "%Y-%m-%d%X%:z")
print(...
0
votes
1
answer
59
views
datetime.strptime() is blocking asyncio.Queue.get() [duplicate]
In the following code datetime.strptime() is blocking asyncio.Queue.get() operation
import time
import asyncio
from datetime import datetime
from functools import partial
def write(queue):
data =...
0
votes
0
answers
91
views
pyqtgraph: Show x axis labels in the form DD HH:MM:SS of data representing timedeltas with DateAxisItem
I am trying to use pyqtgraphs DateAxisItem for relative times on the x axis, i.e., durations (which can be between a few hours and several days). I know I could simply use an ordinary AxisItem and ...
0
votes
1
answer
70
views
I have a time in string format, which is of New York. I want the time to be converted to UTC in Python
Input (New York Time in string format) = '2024-11-01 13:00:00'
Output (UTC Time in string format) = '2024-11-01 17:00:00'
2
votes
2
answers
156
views
Determine whether a given date string includes all three components: day, month, and year
I am trying to determine whether a given date string includes all three components: day, month, and year.
Example Inputs and Expected Outputs:
"2025-01-01" → True (All components are ...
0
votes
1
answer
64
views
Python Async Function not updating timestamp
I have a machine running some scripts that I need to keep an eye on.
I have set up a script in python to send me emails using every hour.
I would like to add timestamp to it so that I can see at a ...
0
votes
1
answer
112
views
How to save dataframe after shifting its columns using date as index
When I use .shift() from Pandas on a column in a DataFrame with a date index, I can use it, for example, with .corr(), but I cannot update my old DataFrame or create a new one.
Dataset
My df looks ...
1
vote
2
answers
109
views
In python (pytz), how can I add a "day" to a datetime in a DST-aware fashion? (Sometimes the result should be 23 or 25 hours in in the future)
I'm doing some datetime math in python with the pytz library (although I'm open to using other libraries if necessary). I have an iterator that needs to increase by one day for each iteration of the ...
-1
votes
1
answer
358
views
Pandas Datetime conversion CET/CEST to UTC
I have a df datetime column that I want to convert from Europe/Copenhgaen t.z to UTC but I just keep getting duplicate entries in the UTC column. The reason this happens is because of how I make my ...
1
vote
1
answer
66
views
Why cannot I not maintain the timezone information with matplotlib mdates
I need to plot some patches which requires me to use the matplotlib mdate module (ideally) to have control over the tick markers. I have used mdates before and I can't for the life of me figure out ...
0
votes
1
answer
58
views
How do I get the time difference between 2 sets of datetime objects in hours? Python
I'm connecting to an API that returns a list of articles, each article has created_at and modified_at properties. I want to return the difference (in hours) between the created_at and modified_at ...
0
votes
1
answer
49
views
How to create Python `datetime` in a specific timezone? [duplicate]
Input:
import pytz
from datetime import datetime as dt
targettz = pytz.timezone('America/New_York')
d1 = dt(2024, 1, 1, 7, 40, 0, tzinfo=targettz)
d1.isoformat()
Output:
'2024-01-01T07:40:00-04:56'
...
2
votes
1
answer
829
views
Python datetime format: UTC time zone offset with colon
I'm trying to format a datetime object in Python using either the strftime method or an f-string. I would like to include the time zone offset from UTC with a colon between the hour and minute.
...
-2
votes
1
answer
47
views
Is there a way to convert days from the datetime import into an integer [duplicate]
I am fairly new to programming and to practice I decided to make a program to calculate how many days you have been alive and then convert that into how many hours you have been alive. However, I have ...
0
votes
2
answers
63
views
python datetime.datetime respecting tzinfo but datetime.time is not
In python 3.9:
datetime.datetime respects tzinfo but datetime.time does not appear to.
import datetime
from zoneinfo import ZoneInfo
dta = datetime.datetime.now(tz=ZoneInfo("America/Los_Angeles&...
0
votes
1
answer
53
views
python & mongoengine, How do I map data to datetime?
I am trying to store temporal data in mongodb with the use of mongoengine. As the date of the data is a primary component, I thought it would be best to map the data to the date. However, when ...
2
votes
0
answers
93
views
Can I easily parse datetimes independently of my machine?
In python I like the datetime module of the standard library to parse timestamps.
However, some of the format codes depend on the locale set for the machine where it's run, which makes the code ...
0
votes
1
answer
38
views
Iteration column with Day's name
I Would like to Compare the Nasdaq's Monday's daily performance with the PREVIOUS Friday's performance, if they are the same record event in a counter.
I create a column that specifies if Nasdaq went ...
0
votes
3
answers
94
views
How can I parse a date time string with the 'WET' timezone
I am trying to parse a date string like this:
import datetime
document_updated_on = '01-Feb-2024#15:22 WET'
format_str = "%d-%b-%Y#%H:%M %Z"
updated_on_date = datetime.datetime.strptime(...
-3
votes
1
answer
45
views
How can i fetch given day of any given year?
I'm working on a local program in which I want the first day of the given number of year like(Monday, Tuesday etc). How can I have it?
firstly I try datetime module for this purpose but it gives ...
0
votes
0
answers
178
views
Why is time_machine returning a wrong date?
The time_machine module in python keeps setting a time that is one day earlier than the date that I set.
I must be missing something obvious!
Here's an example of a simple program showing the ...
0
votes
1
answer
40
views
How do I add 'week of year' and 'day of year' columns to a python datatable?
There is currently (version 1.1.0) no python datatable.time.week() or datatable.time.day_of_year() functions.
Here is some example data:
from datetime import date
import datatable as dt
DT = dt.Frame({...
0
votes
1
answer
73
views
Multi-level rolling average with missing values
I have data on frequencies (N), for combinations of [from, to, subset], and the month. Importantly, when N=0, the row is missing.
N from to subset
month ...
1
vote
0
answers
31
views
pd.to_datetime() not working for old dates [duplicate]
When trying to convert the "Date" field of a pandas DataFrame using pd.to_datetime(), I get an "OutOfBoundsDatetime" error only when the date is before Year 1700 (otherwise the ...
0
votes
1
answer
55
views
How can I modify this script to select any folders dated in the last 12 months?
I have a folder directory (shown below) that contains folders titled "year-month." They will be continuously added over time. I am trying to write a python code that selects any files in ...
1
vote
1
answer
105
views
How to set the number of tick marks for the X axis in matplotlib pyplot
I am trying to set the number of tick marks for both the x and y axis to 12. However, only the y axis is being set and the x axis stays the same. I am using the locator_params to set both axis.
plt....
1
vote
2
answers
219
views
How can I make the x-axis of my 2D histogram use dates while avoiding overflow errors from matplotlib axis formatting?
I am working with a set of monthly averaged time-series data that spans 20+ years and have put the data into a pandas dataframe. The index of the dataframe is composed of the datetime objects that ...
0
votes
2
answers
59
views
Possible to vectorize date arithmetic with different offset per row?
I have a simple function get_start_of_period which takes in a date and returns the start of that period. It looks as follows:
import datetime as dt
from dateutil.relativedelta import relativedelta
...
0
votes
1
answer
366
views
Converting UTC Column into datetime in python pandas
I would like to ask for little support. I have here a python frame containing data giving in UTC format. I would like to transform the column into date-format.
Order Date
15-Feb-2024 UTC
17-Feb-2024 ...
0
votes
2
answers
116
views
How to find the first market day of each month in Python?
I'm trying to figure out how to find the first market day of each month and to wait until each of those days after running some logic. I've figured out some of the code to be able to do this, but I ...
3
votes
1
answer
79
views
Pandas bug when trying to loc data on a quarter
With a dataframe that has a datetime index, I am used to getting data for quarters with the syntax eg. df.loc["2014-Q1"] to grab the data for the first quarter of 2014 (Jan, Feb, Mar).
This ...
0
votes
1
answer
165
views
Iterate through rows in excel spreadsheet and find the difference in time when values in a different column are zero
This code iterates through an excel spreadsheet and finds a specific column where energy is zero, then calculates the duration of that zero-energy-value period by calculating difference between first &...
0
votes
1
answer
58
views
Python datetime.replace() has unexpected behaviour when uploading to Firebase Firestore
For testing purposes, I have deployed the following Firebase Cloud Function. When the function gets called, it adds a document to my Firestore collection with two fields containing two datetimes.
@...
0
votes
1
answer
224
views
mktime resulting in OverflowError: mktime argument out of range
When attempting to get a time using mktime, I get a overflow exception. This occurs on a Debian docker image, but not on my host machine:
docker pull python:3.9.7
https://hub.docker.com/layers/...
3
votes
1
answer
2k
views
Current Timestamp in Azure Databricks Notebook in EST
I need the current timestamp in EST but the current_timestamp() is returning PST.
Tried the following code but it's not working and showing 6 hours before EST time:
# Import the current_timestamp ...
1
vote
0
answers
761
views
DateTime conversion (March 5, 2024, 5:33 a.m. to datetime.datetime(2024, 3, 5, 5, 33)) [duplicate]
i have
raw date = March 5, 2024, 5:33 a.m.
is it possible to convert it in
datetime.datetime(2024, 3, 5, 5, 33)
using python
I have tried
from datetime import datetime
date_string = "March 5, ...
-1
votes
1
answer
65
views
Can't calculate the difference between two dates using datetime
I was trying to caltculate the date using datetime module, but when I entered 1 in define dates it showed me:
41 days, 0:00:00
Traceback (most recent call last):
File "", line 22, in <...
0
votes
2
answers
89
views
Replacing NaN in dataframe with datetime index by dict doesn't work
I have a dict with hourly measurement data where some entries are missing (gaps). My current approach is to create a dataframe with an hourly datetime index and prefilled with NaN. Then replace the ...
0
votes
0
answers
33
views
I am getting value error while parsing it to date time format in pandas [duplicate]
ValueError: time data "44033" doesn't match format "%d/%m/%Y", at position 0.
You might want to try:
- passing format if your strings have a consistent format;
- passing format='...
0
votes
1
answer
25
views
Labelling data set with year, month,date and times
I have few data as follows:
0.907752
0.916137
0.923206
0.919096
0.928631
........
0.922548
and I want to do is to insert year ,month, date and time in the data as follows:
2012-12-01 00:00:00 0.907753
...
7
votes
2
answers
2k
views
How to catch DateParseError in pandas?
I am running a script that uses pd.to_datetime() on inputs that are sometime not able to be parsed.
For example if I try to run pd.to_datetime('yesterday') it results to an error
DateParseError: ...
0
votes
2
answers
84
views
How to label the x-axis only with hour:min in matplotlib (using datetime)?
I am trying to create a plot using time in the hour:min format on the x-axis and some values on the y-axis. The data on the x-axis is built using the datetime.datetime method. However, the figure ...
0
votes
1
answer
153
views
Get the local time without daylight savings applied, using the latest methodology
I am trying to get the local time without the application of daylight savings time.
I know that I can get the local time with the following, but when my location is in DST I get an extra hour. I want ...
2
votes
1
answer
644
views
Is this expected behavior for Python Datetime with timezone inserted into Postgres DB using sqlalchemy orm? What's going on?
Summary
Inserting datetime with timezone object into postgres column without timezone appears to first convert to a local timestamp and then removes the offset. Eg for 2024-01-15 19:04:38.921936+00:00 ...
0
votes
1
answer
708
views
Checking if a user is less than 18 years old [duplicate]
Hi im new in programming in python with datetime (and in general to be honest).
So im doing a project where I need to check if the user is more than 18 years old. I used timedelta to get the ...
5
votes
1
answer
200
views
Lengths of overlapping time ranges listed by rows
I am using pandas version 1.0.5
The example dataframe below lists time intervals, recorded over three days, and I seek where some time intervals overlap every day.
For example,
one of the overlapping ...