0

I have a dataframe like this that contains a call center data:

In [3]: cluster_data.head()
Out[3]:
        queue_id  agent_id call_datetime  ...     caller_id  waiting  duration
id                                        ...
100001        15       NaN  10/1/18 0:00  ...  2.490655e+13       36         0
100002        11    1135.0  10/1/18 0:01  ...  2.900872e+13        8       266
100003        11    1154.0  10/1/18 0:02  ...  8.442416e+12       85        78
100004        16    1594.0  10/1/18 0:02  ...  2.288829e+12       39      3040
100005        20    1343.0  10/1/18 0:02  ...  2.735932e+10        9       192

what I want to do is to count the number of calls by users that happened in each day.

I did it by groupby function and the result is like this

transformed = df.groupby('day')['caller_id'].value_counts()

day  caller_id
01   3.413120e+13    13
     6.720000e+03    11
                     ..
16   3.352196e+13     1
     3.369415e+13     1
     3.480403e+13     1

now I want to write it back to my dataframe how can I do that? something like this:

Out[3]:
        queue_id  agent_id call_datetime  ...     caller_id  waiting  duration  count
id                                        ...
100001        15       NaN  10/1/18 0:00  ...  2.490655e+13       36         0  1
Mohammad Reza
  • 1,143
  • 4
  • 13
  • 27

0 Answers0