dt accessor
noun
say it: “dot DEE-TEE ak-SESS-er” /dɑt ˌdiˈti ækˈsɛsər/
In pandas, the .dt part of a date column, which gives it date tools such as the year, the month or the day of the week for every row at once.
What is the dt accessor in pandas?
The dt accessor is .dt, read "dot d t": it gives a pandas date column its date tools, such as year, month,
hour and day_name(), each working on every row at once, as .str does for text. It works only on a column that
holds real dates.
signed_up = pd.to_datetime(regs["registered_at"])
print(signed_up.dt.day_name().value_counts()) # sign-ups for each day of the week
In a sentence
- “With the dt accessor, the race director counted sign-ups by hour of the day.”
- “The dt accessor only works once the column holds real dates.”
Level: Journeyman · More Python terms at this level
Updated