pandas Datetime, Time Zone and Resampling Walkthrough
Handle timestamps correctly and aggregate by period.
The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.
[VERIFY] is an editorial flag, not a blank to fill. Wherever the prompt shows [VERIFY], check that item against a reliable source before you use it.
Teach me to handle dates and times in pandas on my data. Columns and sample values (invented or anonymised) including formats and time zones: [DATE_COLUMNS_AND_SAMPLES]. What I need (daily totals, weekly averages, business days, month-end comparisons): [GOALS]. The time zone of the source and of the report: [TIME_ZONES]. Show, with code blocks and the expected output for a ten-row sample: parsing dates with an explicit format, detecting failures, localising and converting time zones, handling daylight saving transitions, extracting parts, and resampling to day, week and month with sum or mean. Be explicit about assumptions on time zones and week starts: a week can start on Monday or Sunday, which changes totals. Worked example: three sales at 23:30 UTC on the 31st fall on the 1st in a time zone five hours ahead, changing monthly totals. List common errors (mixed formats, two-digit years, day-first ambiguity) and how to detect each. Write tests checking the number of days, the first and last date, and missing periods. Where behaviour differs between versions or systems, say so and tag it [VERIFY].
Fill in before use
Optional: type your details and the prompt above updates. Nothing is saved or sent.
Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.