I'm getting dates from my API in iso format.
When I'm doing:
df = DataFrame(results)
df.to_csv(path_or_buf=file_name, index=False, encoding='utf-8',
compression='gzip',
quoting=QUOTE_NONNUMERIC)
And I look at the CSV I see for example:
lastDeliveryDate
2018-11-21 16:25:53.990000-05:00
However,
When I do:
df = DataFrame(results)
df.to_json(path_or_buf=file_name, orient="records",compression='gzip', lines=True)
I see (other record):
"lastDeliveryDate":1543258826689
This is a problem.
When I load the data from the CSV to Google BigQuery eveything is fine. The date is parsed correctly.
But when I changed the loading to Json. It doesn't parse the date correctly.
I see the dates in this format:
50866-01-09 23:46:40 UTC
This occurs because the to_json()
and to_csv()
produce different results for dates in iso_format
How can I fix this? Must I edit the data frame and convert all my dates columns to regular UTC? how can I do that? and why it's needed for to_json()
but not for to_csv()
?
as explained at How do I translate an ISO 8601 datetime string into a Python datetime object? Tried to do:
df["lastDeliveryDate"] = dateutil.parser.parse(df["lastDeliveryDate"])
But it gives:
TypeError: Parser must be a string or character stream, not Series