ENH: Add date_format
and date_unit
to to_dict
similar to what exists in to_json
#60656
Open
1 of 3 tasks
Labels
Closing Candidate
May be closeable, needs more eyeballs
Enhancement
IO Data
IO issues that don't fit into a more specific label
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
df.to_dict
is often (maybe even mostly) to post data via REST API.My usual workflow for posting data looks like this:
Ideally, the datetime to string could happen inside of
to_dict
via an optionaldate_format
anddate_unit
parameter similar todf.to_json
.However,
df.to_json
is not a suitable alternative because often I need to add an additional key as seen above.If this seems like an appropriate new feature, I will dig into how to implement this.
Feature Description
Add 2 new parameters to
to_dict
:date_format
. Possible values: None, Epoch, isoformat. Default: None. If None, do nothing.date_unit
. One of ‘s’, ‘ms’, ‘us’, ‘ns’ . Default msAlternative Solutions
None really
Additional Context
Code for to_dict:
pandas/pandas/core/methods/to_dict.py
Line 56 in 1be2637
to_json: https://github.com/pandas-dev/pandas/blob/v2.2.3/pandas/core/generic.py#L2428-L2717
The text was updated successfully, but these errors were encountered: