Open dshean opened 12 hours ago
Thanks for the request. Can you provide input, a proposed syntax for the operation, and what your expected output would be.
Sure. Something like df['dt_col'].dt.decyear
could work well, using the dt
accessor.
Would convert column of datetime64 (e.g.,2024-11-15 12:13:12+00:00
) to float64 (e.g., 2024.872976
)
@rhshadrach if you don't mind, I would love to work on this issue
Feature Type
[X] 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)