Created
February 27, 2019 03:26
-
-
Save liquidgenius/195fd7ca99fb761fd0fd2c2f2c78608d to your computer and use it in GitHub Desktop.
Converts a Pendulum datetime to a Pandas datetime
This file contains hidden or 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
def pendulum_to_pandas(pend_dt): | |
"""Converts a Pendulum datetime to a Pandas datetime | |
Parameters | |
----------- | |
pend_dt (Pendulum.datetime): Any Pendulum datetime. Pendulum datetimes include | |
nanoseconds that Pandas does not support. | |
Returns | |
-------- | |
results (Pandas friendly datetime): A Pandas friendly datetime excluding nanoseconds. | |
""" | |
# Drop nanoseconds | |
results = pend_dt.strftime("%Y-%m-%d %H:%M:%S %z") | |
return results | |
def series_of_dates(start, end): | |
period = pendulum.period(start, end) | |
period_days = [pendulum_to_pandas(dt) for dt in period.range('days')] | |
results = pd.Series(period_days) | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment