Skip to content

Instantly share code, notes, and snippets.

@westonpace
Created August 13, 2021 06:04
Show Gist options
  • Save westonpace/23fc1baee017e2aa5c9d6d5825d34bdf to your computer and use it in GitHub Desktop.
Save westonpace/23fc1baee017e2aa5c9d6d5825d34bdf to your computer and use it in GitHub Desktop.
Converting a time string to a time64 using python (better methods exist in pyarrow >= 6.0.0, or use pandas)
import pyarrow
from datetime import datetime
start = datetime.strptime("00:00", "%H:%M")
time = datetime.strptime("12:15", "%H:%M")
delta = time - start
us = int(delta.total_seconds() * 1000000)
print(pyarrow.array([us], type=pyarrow.int64()).cast(pyarrow.time64('us')))
# <pyarrow.lib.Time64Array object at 0x7f0b7acad160>
# [
# 12:15:00.000000
# ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment