Sunday, 5 March 2023

Predict inventory stock end date using Python

Here's an example Python code that predicts the end date of inventory stock based on the current stock level and average daily sales:


from datetime import date, timedelta


# Current stock level

current_stock = 1000


# Average daily sales

avg_daily_sales = 50


# Calculate days until stock runs out

days_until_empty = current_stock / avg_daily_sales


# Calculate end date of inventory stock

end_date = date.today() + timedelta(days=days_until_empty)


# Print end date in YYYY-MM-DD format

print(end_date.strftime('%Y-%m-%d'))

In this example, we assume that the current stock level is 1000 and the average daily sales are 50. We calculate the number of days until the stock runs out by dividing the current stock by the average daily sales. We then add this number of days to today's date to get the end date of the inventory stock. Finally, we print the end date in the YYYY-MM-DD format.

Python code to predict inventory stock end date

 To predict the inventory stock end date, you need to have some data about inventory levels over time. Here's an example Python code that uses historical sales data to predict the inventory stock end date:


```python

import pandas as pd

import numpy as np

from datetime import timedelta, datetime


# Load sales data

sales_data = pd.read_csv('sales_data.csv')


# Convert date column to datetime format

sales_data['date'] = pd.to_datetime(sales_data['date'])


# Calculate daily sales

daily_sales = sales_data.groupby('date').sum()['sales']


# Calculate rolling average of daily sales over the last 7 days

rolling_avg = daily_sales.rolling(window=7).mean()


# Calculate average daily sales over the last 7 days

average_daily_sales = rolling_avg.iloc[-1]


# Calculate current inventory level

current_inventory = 1000


# Calculate number of days until inventory runs out

days_until_stockout = np.floor(current_inventory / average_daily_sales)


# Calculate predicted stock end date

stock_end_date = datetime.today() + timedelta(days=days_until_stockout)


print('Predicted inventory stock end date: ', stock_end_date)

```


This code loads in sales data and calculates the daily sales, rolling average of daily sales over the last 7 days, and the average daily sales over the last 7 days. It then calculates the number of days until the inventory runs out based on the current inventory level and average daily sales, and finally predicts the inventory stock end date by adding the number of days until stockout to today's date.