import pandas as pd
data = {'SKU': ['A', 'A', 'A', 'A',
'B','B','B','B',
'C','C','C','C',
'D', 'D', 'D', 'D',
'E', 'E', 'E', 'E',
'F', 'F', 'F', 'F'],
'Current_Stock': [2,0,0,0,
0,0,-1,-1,
2,-1,0,1,
2,2,3,1,
2,0,0,1,
2,-1,1,0],
'Date_Updated': ['2024/7/26', '2024/7/27','2024/7/28', '2024/7/29'
'2024/7/26', '2024/7/27','2024/7/28', '2024/7/29',
'2024/7/26', '2024/7/27','2024/7/28', '2024/7/29',
'2024/7/26', '2024/7/27','2024/7/28', '2024/7/29',
'2024/7/26', '2024/7/27','2024/7/28', '2024/7/29',
'2024/7/26', '2024/7/27','2024/7/28', '2024/7/29']}
df = pd.DataFrame(data)
result = pd.DataFrame({'SKU': ['A', 'B', 'C', 'D', 'E', 'F'],
'Days_Out_of_Stock': [3,4,0,0,0,1]})
My desire is to calculate number days of out of stock, which is
- If all days which current_stock < 1, the number days of out of stock = sum of all days (Eg: sku B)
- If any recent days is restocked, the number days of out of stock will be calculated again from that day (Eg: sku C)
Thanks for advance