Skip to content

TimeUnit 'day' parsed differently for Pandas DataFrame and .csv data #3737

Answered by jakevdp
robmitchellzone asked this question in Q&A
Discussion options

You must be logged in to vote

CSV is fine as long as dates are represented by the full ISO-8601 string. If you use Altair's data transformers rather than pandas, it will do the right thing.

The fundamental issue stems from javascript's built-in date parsing, which is what the Vega-Lite renderer uses to parse dates stored as strings:

> new Date('2020-11-20')
Thu Nov 19 2020 16:00:00 GMT-0800 (Pacific Standard Time)
> new Date('2020-11-20T00:00:00')
Fri Nov 20 2020 00:00:00 GMT-0800 (Pacific Standard Time)

When you pass a dataframe to alt.Chart, Altair ensures that dates are serialized as full ISO-8601 strings, and so they will be parsed correctly. Pandas to_csv() does not do this, and so Javascript parses the resulting…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by dangotbanned
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #2413 on January 02, 2025 14:27.