1

I have a dataframe with two series:

  1. Date of Call
  2. Sales Rep

The dataframe is a list is all calls to customers made by a sales force over the course of one year - one row for each call. The date field is the date of the call, and the "Sales Rep" is the person who made the call. There are approximately 250k rows in the dataframe.

I'd like to summarize this data into a new dataframe with the index being the sales reps and the columns being the number of calls by month i.e. one row for each sales rep and one series for each month. I thought pd.Pivot was the way to go but that didn't work.

What's the easiest and most pythonic way to achieve this results?

Steve Maughan
  • 1,174
  • 3
  • 19
  • 30
  • is [this](http://pbpython.com/pandas-crosstab.html) what you need? – Maarten Fabré Oct 23 '18 at 12:44
  • please also provide some sample data and expected outcome, and what you already tried – Maarten Fabré Oct 23 '18 at 12:44
  • See the section on `crosstab` – piRSquared Oct 23 '18 at 12:50
  • This isn't a duplicate question. The question it supposedly duplicates is a general discussion of aggregating data, and there is no discussion of time based data. If this question is classed as a duplicate then I suggest virtually all `pd.groupby` questions are also duplicates of the same question. – Steve Maughan Oct 24 '18 at 00:15

1 Answers1

2

I believe you need crosstab:

df = pd.crosstab(df['Sales Rep'], df['Date of Call'].dt.month)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252