Skip to content

Instantly share code, notes, and snippets.

@liquidgenius
Created February 27, 2019 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liquidgenius/195fd7ca99fb761fd0fd2c2f2c78608d to your computer and use it in GitHub Desktop.
Save liquidgenius/195fd7ca99fb761fd0fd2c2f2c78608d to your computer and use it in GitHub Desktop.
Converts a Pendulum datetime to a Pandas datetime
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