ENH: Decimal year #60391
Labels
Datetime
Datetime data dtype
Enhancement
Needs Info
Clarification about behavior needed to assess issue
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
I wish I could use pandas to quickly convert datetime/Timestamp objects to "decimal year" floating point numbers for subsequent visualization and analysis.
A number of plotting packages (e.g., GeoPandas, matplotlib) encounter issues when casting datetime/Timestamp objects to float. For example, I often encounter errors when trying to create a choropleth map to visualize a GeoDataFrame column containing datetime objects. Decimal years also simplify the legend/colorbar labels.
Feature Description
This is a simple function to accomplish this. It's not perfect, but does the job. Would need to re-implement as a Timestamp and/or dt accessor property (
dt.decyear
). Should be relatively simple, I think.Alternative Solutions
Define and apply a custom function:
df['dt_col_decyear'] = df['dt_col'].apply(toYearFraction)
Additional Context
When attempting to plot column containing datetime values...
gdf.plot(column='dt_col', legend=True)
The text was updated successfully, but these errors were encountered: