Search code examples
python-3.xinventory-management

Not able to make a class in Python and output it to excel


I'm fairly new in Python and working in a inventory management position. One important thing in inventory management is calculating the safety stock.

So, this is what I'm trying to achieve.

I have imported a file with 3 columns; FR, sigma and LT for 3 rows. See hereunder the code and the output:

code:

import pandas as pd
df = pd.read_excel("Desktop\\TestPython4.xlsx")
xcol=["FR","sigma","LT"]
x=df[xcol].values

output: snapshot

To calculate the safety stock, I have the following (simplified) formula of it;

CDF(FR)*sigma*sqrt(LT)

where CDF is the cumulative distribution function of the normal distribution and FR is a number between 0 and 1 (thus the well-knowned z-value is the output).

I want to output a the file with an extra column that displays the safety stock. For this I made a class safetystock with the following code:

class Safetystock:
def __init__(self,FR,sigma,LT):
    self.FR = FR
    self.sigma = sigma
    self.LT = LT
    pass

def calculate():
    SS=st.norm.ppf(FR)
    return print(SS*sigma*np.sqrt(LT))
    pass

Then I made the variable: "output"

Output = Safetystock(df.FR,df.sigma,df.LT)

I said that the data in the file needs to be taken into account. Then I added a column to df, named output that needs to contain the variable "Output":

df["output"]=Output

Now, when I want to call df, it gives me this:

actual output

What am I doing wrong?

Cheers,

Steven


Solution

  • What about

    import pandas as pd
    import numpy as np
    import scipy.stats as st
    
    df = pd.read_excel("Desktop\\TestPython4.xlsx")
    df["output"] = st.norm.ppf(df.FR)*df.sigma*np.sqrt(df.LT)