Skip to content

Instantly share code, notes, and snippets.

@bruno-uy
Last active May 17, 2021 20:55
Show Gist options
  • Save bruno-uy/035dab09f723d369103d57cedbd575de to your computer and use it in GitHub Desktop.
Save bruno-uy/035dab09f723d369103d57cedbd575de to your computer and use it in GitHub Desktop.
Date frequency group by month
import pandas as pd
# Create sample pandas.Series to calculate frequency
s = pd.Series(pd.date_range("2021", freq="18H", periods=1000))
# Calculate frequency grouping by month
# If you want another period check following link:
# https://pandas.pydata.org/docs/user_guide/timeseries.html#timeseries-offset-aliases
freq_count = s.dt.to_period("M").value_counts(sort=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment