Skip to content

Instantly share code, notes, and snippets.

@Tdual
Created July 4, 2020 13:36
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 Tdual/44d3c6ab11c30e951f12f24ca6ed2c39 to your computer and use it in GitHub Desktop.
Save Tdual/44d3c6ab11c30e951f12f24ca6ed2c39 to your computer and use it in GitHub Desktop.
infer_freq
def infer_freq(self, pd_series):
d = {
"A": "year",
"M": "month",
"W": "week",
"D": "day",
"H": "hour",
"T": "min",
"S": "sec",
"L": "millisec",
"U": "microsec",
"N": "nanosec"
} # ref: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html
rep = pd.DatetimeIndex(pd_series).inferred_freq
unit = re.sub("\d", "", rep)
freq = d.get(unit)
return freq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment