Want to find which time period contains a Python Pandas datetime? Use to_period: This returns a Pandas “Period” object, useful (among other things) for checking if two dates are within the same period.
Want to find leap years in a Python Pandas datetime series? Use dt.is_leap_year:
Want to know if values in a Python Pandas datetime series are at the start/end of a period? Get a boolean series from:
Use dt.day_of_week to get the day number from a Python Pandas datetime series. But is 0 Sunday or Monday? Or not used at all? Better: Use the day_name method: Good news: It returns a series of strings!Bad news: It’s 4x slower.
Want to grab a part of datetime value in a Python Pandas data frame column? Use “dt”: day_of_week returns an integer, where 0 is Monday and 6 is Sunday.
Reading a CSV into Python Pandas, and parse_dates doesn’t recognize the format? Pass the date_format keyword arg: All strftime codes work!
If you’re like me, then you’ve lately been exploring agentic coding, having AI write code on your behalf. What will be the impact on our work developing software? On hiring? On training? From what I can tell, the question isn’t whether we’ll be using agentic coding, but how we do so. Knowing how AI writes…
Reading a CSV into Python Pandas, and want a column to be treated as datetime values? Use parse_dates: Bonus: The PyArrow engine often (not always) parses columns that look like dates.
Want to take a Python Pandas series of strings, and get datetime values? Use pd.to_datetime: Notice: It’s not a method! It’s a top-level pd function. Specify a non-standard “format” with a strftime string:
If a Python string contains an ISO-formatted date, skip strptime and use datetime.fromisoformat: