Description
Is your feature request related to a problem?
I wish I could use pandas to store a column of timezone-aware datetime values with different timezones in a series with a datetime64
dtype. In certain applications it is desirable to perform operations on all columns of a certain type, and currently a column with mixed types gets stored as object
which makes it difficult to programmatically identify the column as containing datetime values based on the dtype and the object
dtype prevents doing things like accessing the day of the datetime with the .dt
accessor.
Describe the solution you'd like
I would like to have the ability to store a series of timezone aware values with mixed timezones and use the .dt
accessor to access the underlying datetime components:
mixed_tz_series = pd.Series([
pd.to_datetime("2018-03-01").tz_localize(tz="US/Pacific"),
pd.to_datetime("2018-03-01").tz_localize(tz="US/Central"),
pd.to_datetime("2018-03-01").tz_localize(tz="Europe/Vienna"),
], dtype="datetime64[ns]")
mixed_tz_series.dt.day
API breaking implications
None that I'm aware of.
Describe alternatives you've considered
Instead of using the .dt
accessor on the series, one could use apply
with a lambda function (or other function) to get at the underlying date components, but this does not address the fact that the series is not stored with a datetime
dtype, making it more difficult to determine that the datetime operations could/should be applied to the column.