Pandas/Time series 8 min
Datetime columns and indexes
Parse dates once, then slice time like a pro.
to_datetimedtindex
Dates arriving as text should be converted once with pd.to_datetime. After that the .dt accessor exposes every calendar part as a column.
python · editable
loading editor…
Try it: Add an is_weekend column using dt.dayofweek.
Setting the date as the index unlocks string-based slicing: pass a partial date and pandas selects the whole period.
python · editable
loading editor…
If dates still show up as object dtype, the parse silently failed on some rows. Pass format= or errors='coerce' and inspect the NaTs.
practice this