I have the following dataset (sample) from which I have to extract dataframe based on a condition. The dataset consists of machines (over 1000), the downtime in hours, the status, and the downtime reason. There are many instances of each machine in the dataset (at least 1000). The condition for extraction is the dataframe must only contain those machines that have been active for the past 7 days consecutively (including the date). The dataset does not contain records for every day for each machine. Some days have been skipped. For those days, I'm not sure if the machine was active or not. I'm trying to do it on a rolling basis, for example, for the date in each row, I'm trying to check if that unique machine has been active for the past 7 days (pd.Timedelta(days = 6)). I think there is a neater and more organized way to achieve this but so far, I've not been able to come up with an algorithm. I'm pretty much a novice programmer in Python. Is there someway I can organize the machines and then check for each date. I would also like to be able to keep track of those machines for which records for some days have been skipped. I don't need the code in Python. I'd just greatly appreciate if someone could help me come up with an effective algorithm through which I can achieve the new dataframe.
Thank you very much in advance and happy holidays! :)
| DATE | MACHINE | DT_IN_H | MACHINE_STATUS | DT_REASON |
|---|---|---|---|---|
| 11/5/2021 | 710 | 0 | ACTIVE | In Service |
| 8/1/2020 | 847 | 0 | ACTIVE | In Service |
| 2/4/2020 | 1334 | 0 | ACTIVE | In Service |
| 5/16/2020 | 855 | 24 | ACTIVE | Under mgmt |
| 1/4/2019 | 669 | 0 | ACTIVE | In Service |
| 7/24/2021 | 1831 | 0 | ACTIVE | In Service |
| 10/19/2018 | 134 | 24 | ACTIVE | Under mgmt |
| 8/18/2019 | 395 | 0 | ACTIVE | In Service |
| 1/19/2019 | 499 | 24 | ACTIVE | Under mgmt |
| 7/24/2020 | 2085 | 0 | ACTIVE | In Service |