Vectorizing Loop-based Time-Series Algorithm

Job ID: 38949947

Budget: $30 – $250 USD

### Task Overview:
I need a **Pandas DataFrame expert** to **vectorize a loop-based algorithm** for time-series data. The task involves complex calculations to eliminate the need for Python loops, ensuring the solution is efficient and fast.

---

### DataFrame Details:
The DataFrame contains the following columns:
- `used_res` (Resource Used)
- `res_cap` (Resource Capacity)
- `qty` (Quantity)

---

### Algorithm Requirements:

1. **Step 1: Calculate Desired Quantity**
- Compute the percentage:
`percent_used = used_res / res_cap`
- If `percent_used > target_value` (a static threshold variable), calculate `desired_qty` using the formula:
```python
desired_qty = ceil(qty * (percent_used / target_value))
```
- Store the result in a new column: `desired_qty`.

2. **Step 2: Update Quantities Based on Conditions**
- Create another column: `updated_qty`.
- Logic for updating:
- If `desired_qty[index] > desired_qty[index - 1]`, then:
```python
updated_qty[index + 10] = desired_qty[index]
```
- If `desired_qty[index] <= desired_qty[index - 1]`, then:
```python
updated_qty[index + 5] = desired_qty[index]
```

- Ensure this is handled without using loops, `iterrows`, or `itertuples`. The entire process must be vectorized for performance.

---

### Deliverables:
1. A Python function/script implementing the vectorized solution using Pandas.
2. Verify correctness by ensuring the output matches the provided "before" and "after" CSV files.
3. Provide clean, well-documented, and maintainable code.

---

### Notes:
- The solution **must not use loops** or row-based iteration functions like `iterrows` or `itertuples`. Efficiency is critical.
- Use Pandas vectorization techniques and NumPy functions where appropriate.
Related categories: Python Data Science Pandas