Handling Date column during file import

When you import data with typed turned on. Columns that contain date information such as ‘Year’ are interpreted as number type.

data = FileAttachment("somedata.csv").csv({typed: true})

Wonder if it is possible to declare certain columns as date types during import itself.

Example: Disasters in South Eastern Asia (1900 - 2021) / Arky / Observable


thanks for commenting on Smarter formatting for year channels? · Issue #768 · observablehq/plot · GitHub

I wonder about a possible solution which would be to introduce a Plot.year() helper that would read in a date in “any format” (string, Date or number), and return a (UTC) year?


It might need some flags too.
I was parsing years and because of my timezone the years were being changed to last year.

Or was doing it wrong.

Still I like @arky’s idea and would like to see an typed structure parsed to instruct they types of some element. ({typed: {'key':'type','key':'type'...})

Let’s see how this is handled in other tools.

In pandas you can pass parse_dates parameter to pandas.read_csv

date_cols = ['col1', 'col2']
pd.read_csv(file, sep='\t', header=None, names=headers, parse_dates=date_cols)

Am going to lean towards resolving this during data preparation stage itself.

It might be very difficult to maintain a dedicated Plot.year() unless it has more advanced features for handling time series and other advanced features.