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 ...
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, ...
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
0
answers
83
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 ...
2
votes
2
answers
154
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
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
votes
1
answer
349
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 ...
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 ...
2
votes
1
answer
817
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.
...
0
votes
2
answers
62
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&...
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
3
answers
90
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(...
0
votes
0
answers
176
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
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 ...
0
votes
1
answer
53
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
2
answers
215
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
1
answer
361
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 ...
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
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.
@...
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
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
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='...
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
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 ...
0
votes
1
answer
704
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 ...