Reputation: 53
I am trying to group the data by month (Created Date) and count the number of tuples for that month using python pandas.
Upvotes: 1
Views: 824
Reputation: 120399
Are you looking for:
# Convert to datetime64 if it's not already the case
df['Created Date'] = pd.to_datetime(df['Created Date'])
df.resample('MS', on='Created Date')['Created Date'].count()
Upvotes: 1
Reputation: 154
You could use
grouped = df.groupby(df["Created Date"].dt.strftime("%Y-%m")).size()
.dt.strftime allows for formatting the date as text, in this case year-month (%Y is the four digit year, %m the month)
Upvotes: 1