Colleagues, help to form a DataFrame based on a given condition.
Source DataFrame available:
ID №Policy Request Request date Decision 123 23ff 10000 2018-01-28 11:36 0 123 23ff 10000 2018-01-29 10:00 5000 123 42rd 25000 2018-06-18 15:10 25000 123 42rd 30000 2018-08-18 18:00 30000 345 23ff 15000 2018-01-28 12:00 10000 345 27fg 50000 2018-09-30 17:35 0 345 81er 30000 2018-09-30 10:15 10000 345 81er 30000 2018-10-20 11:30 10000 678 12rt 55000 2018-12-01 09:25 0 678 12rt 55000 2018-12-15 12:00 45000
It is necessary to count the number of decisions (Decisions) taken for each ID in the frame No. Policy, however with the following restriction - if the decision on the ID within the same No. Policy was made within one month several times, then that decision is 1 ( i.e., within a month, one ID within one #Policy may have several solutions 2, 3 or more - if everything is done within one month, then regardless of the number of requests, you must assume that this is 1 solution).
The result should be approximately as follows
ID №Policy Request Request date Decision count 123 23ff 10000 2018-01-28 11:36 0 0 123 23ff 10000 2018-01-29 10:00 5000 1 123 42rd 25000 2018-06-18 15:10 25000 1 123 42rd 30000 2018-08-18 18:00 30000 1 345 23ff 15000 2018-01-28 12:00 10000 1 345 27fg 50000 2018-09-30 17:35 0 1 345 81er 30000 2018-09-30 10:15 10000 0 345 81er 30000 2018-10-20 11:30 10000 1 678 12rt 55000 2018-12-01 09:25 0 0 678 12rt 55000 2018-12-15 12:00 45000 1
What algorithm to register here mind I will not put: (
count: 0
, and in the sixth:count: 1
? - MaxUID
,NPolicy
,Request_month
- MaxUcount
different. If we always startedcount
from1
and in all subsequent lines for the sameID
andNPolicy
we would put 0 for the same month. Then the logic would be the same and implement such logic - easier - MaxU