Created
August 13, 2021 06:04
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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