timezone

Keep consistent dtype and timezone when concatenating with NaT in pandas

Keep consistent dtype and timezone when concatenating with NaT in pandas Question: I have two pandas DataFrames containing time series that must be concatenated for further processing. One DataFrame contains localized timestamps while the other contains NaT in the time column. When concatenating, the column type changes from datetime64[ns] to object, hindering the further analysis. …

Total answers: 1

datetime timezone not the same on different computer

datetime timezone not the same on different computer Question: I code on my own computer which is set the CET +02:00 (at least now, that will become +01:00 around October, I think. However, the software I create is often used on another computer, which uses standard UTC. Hence, on my computer I have optimized my …

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

Checking pandas Timestamp for timezone string

Checking pandas Timestamp for timezone string Question: In the code below I want to acquire the timezone of a pandas Timestamp supplied to a function: import pandas as pd import pytz timestamp = pd.Timestamp("2022-05-01", tz=’Europe/Paris’) print(timestamp.tzinfo) This prints: Europe/Paris However, I would like to check whether the timezone matches the timezone that I want and …

Total answers: 1

Adding timedelta to local datetime, unexpected behaviour accross DST shift

Adding timedelta to local datetime, unexpected behaviour accross DST shift Question: I just stumbled accross this surprising behaviour with Python datetimes while creating datetimes accross DST shift. Adding a timedelta to a local datetime might not add the amount of time we expect. import datetime as dt from zoneinfo import ZoneInfo # Midnight d0 = …

Total answers: 1

Convert Local time to UTC before 1970

Convert Local time to UTC before 1970 Question: I’m trying to get UTC times for dates before 1970 but tz and tzinfo in Python only contain timezone databases for dates post-1970. If I’m trying to find the UTC time for a date before 1970, say, Bill Clinton’s birthday: August 16, 1946 8:51AM Hope, AK datetime …

Total answers: 1

Two python datetime objects having the same timezone information are printed differently

Two python datetime objects having the same timezone information are printed differently Question: I’d like to convert timezone of a Python’s datetime object, from US/Eastern to UTC. What I did was first making datetime object of US/Eastern timezone, converting it to UTC timezone, and converting it back to the US/Eastern timezone. It is expected the …

Total answers: 1

How to specify time zone information when reading a csv with Pandas

How to specify time zone information when reading a csv with Pandas Question: I have a csv file with a timestamp given in CAT (Central African Time). When I read it in as a pandas dataframe using: df = pd.read_csv(path, parse_dates=["timestamp"], dayfirst=True) I get an error: C:Users..libsite-packagesdateutilparser_parser.py:1218: UnknownTimezoneWarning: tzname CAT identified but not understood. Pass …

Total answers: 2

How can I convert from UTC time to local time in python?

How can I convert from UTC time to local time in python? Question: So, I want to convert UTC date time 2021-08-05 10:03:24.585Z to Indian date time how to convert it? What I tried is from datetime import datetime from pytz import timezone st = "2021-08-05 10:03:24.585Z" datetime_object = datetime.strptime(st, ‘%Y-%m-%d %H:%M:%S.%fZ’) local_tz = timezone(‘Asia/Kolkata’) …

Total answers: 3

How can I get the timezone from an Arrow date object

How can I get the timezone from an Arrow date object Question: I need to retrieve the timezone from an Arrow date object Let’s take this as an example: import arrow arrow_date = arrow.get("2000-01-01", tzinfo="America/Toronto") How can I return this tzinfo exactly as it is in the code above? I tried the following: arrow_date.format("ZZZ") but …

Total answers: 2