ENH: Support for non-nanosecond resolution in read_csv
and to_datetime
#54048
Labels
Dtype Conversions
Unexpected or buggy dtype conversions
Enhancement
IO CSV
read_csv, to_csv
Non-Nano
datetime64/timedelta64 with non-nanosecond resolution
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
I wish I could use the newly added support for
datetime64[ms]
directly in pandas when opening a file.Feature Description
which would return:
Or alternatively, it could also be more explicit:
Alternative Solutions
Currently, the best way I have found to read in a CSV that has entries outside the 1677-2242 range is:
Thus, I am letting numpy to the actual date parsing.
fillna
is needed because the empty cell indata
gets translated tonp.nan
byread_csv
and numpy can't cast that as adatetime64
. (I expected aNaT
but I guess that's another issue anyway).This solution requires that the dates be in ISO8601 format, which is much stricter than
to_datetime
.Additional Context
See my S/O question for more alternative solutions: https://stackoverflow.com/questions/76608166/how-do-i-parse-a-list-of-datetimes-with-a-s-resolution-in-pandas-2
Thanks to ignoring-gravity for the answer, which I reused here.
The text was updated successfully, but these errors were encountered: