Want a Python datetime? Just invoke datetime.datetime: Omitted time units are 0:
Want to compare two Python datetimes? Just subtract, getting a timedelta:
Need the current date and time in Python?
Generate a Python Pandas DatetimeIndex of datetime values, specifying the frequency, by passing freq and a code: This returns a 184-element DatetimeIndex with evenly-spaced datetime values in that period.
Generate a Python Pandas DatetimeIndex of datetime values with pd.date_range: This returns a 10-element series with evenly-spaced datetime values in that period.
Have a Python Pandas series with datetime values, and want all those until now? Compare with pd.Timestamp.now(): This returns the rows from df where the “when” column is before now.
Want to check whether a Python Pandas series contains another string? Use .str.contains: This returns a boolean series, whose index matches that of df. Keep only those rows containing ‘a’:
Keyword-only parameters in a Python function can have a default: Now call it: Remember: parameters with defaults come *after* those without.
Any Python function parameters after *args are keyword-only: Want to give k a value? Use a keyword argument: Don’t need *args? Just use *, and k is keyword only:
How to annotate *args in Python? Just set the elements’ type; we know it’s a tuple: Normally, tuples contain different types. In args, we assume all values have the same type.