0

I have a sample dataframe. This data refers to the calling data of some users. It is shown as below,

 users       contacts   duration    call_type            timestamp                date
7852979384  9614523545  116         Outgoing      2020-09-09 13:45:57.944      2020-09-09
7997145201  9676322541  114         Outgoing      2020-09-07 17:40:37.229      2020-09-07
9521469384  9052178510  0           Missed_call   2020-09-04 12:27:20.353      2020-09-04
9485712390  9978953153  65          Outgoing      2020-09-11 13:53:54.016      2020-09-11
8521486312  9614523545  0           Missed_call   2020-09-11 12:50:50.969      2020-09-11
8521486312  9147528510  0           Missed_call   2020-09-11 12:50:50.969      2020-09-11

From this I need to get the number of missed calls data from contacts and the users who're not answered in 2 days. The expected output is as follows,

  users      no. of contacts
7852979384      5
7997145201      3
9521469384      2

It would be great that anyone can help me on this. Thank You.

Chiyaan
  • 1
  • 1
  • 1
    Please share the expected output. – Mayank Porwal Nov 20 '20 at 13:13
  • 2
    Please review the following: [How to select rows from a DataFrame based on column values](https://stackoverflow.com/questions/17071871/how-to-select-rows-from-a-dataframe-based-on-column-values) [Selecting rows from a Dataframe based on values from multiple columns in pandas ](https://stackoverflow.com/questions/48979561/selecting-rows-from-a-dataframe-based-on-values-from-multiple-columns-in-pandas) – itprorh66 Nov 20 '20 at 13:27
  • @Chiyaan can you please elaborate more on what have you tried(bits of code)? What problems you are facing? – PN10 Nov 21 '20 at 09:57
  • @Chiyaan You should first filter the df based on call_type = Missed_call and then do `groupby` to count number of users. – Yash Kanojia Nov 21 '20 at 11:06
  • Thank you for your response @YashKanojia. If we filter with Missed_call, we will miss outgoing_call data. But we need to compare missed call data with outgoing data and calculate the number of contacts for which when a user got missed call, has he responded to that contact with in 2 days. That needs to be calculated. – Chiyaan Nov 21 '20 at 11:18
  • @Chiyaan Ok. First create date from timestamp columns. You can groupby user,call_type and date. Then iterate for each user when he has a miss_call entries does the latest ongoing call date is less than 2(For checking days use `timedelta`). – Yash Kanojia Nov 21 '20 at 11:27

0 Answers0