Bringing Creativity, Agility, and Efficiency with Generative AI in Industries 24th Edition | Page 60

Unlock the Potential of Open AI in Smart Manufacturing df [' subtotal '] = df [' quantity '] * df [' unit _ cost '] # Sum the subtotal and overhead columns to get the total cost return df [' subtotal ']. sum () + df [' overhead ']. sum ()
# Example import pandas as pd
# Create a sample DataFrame with some data
df = pd . DataFrame ({' quantity ': [ 10 , 20 , 15 , 25 ], ' unit _ cost ': [ 5 , 4 , 6 , 7 ], ' overhead ': [ 100 , 150 , 200 , 250 ]})
# Call the function to calculate the total cost total _ cost = calculate _ total _ cost ( df )
# Print the result print ( f ' The total production cost is ${ total _ cost :. 2f }')
# Output The total production cost is $ 1050.00
Example : Product Simulation # Define a function to simulate the performance of a product under different scenarios
# Input : a pandas DataFrame with columns ' scenario ', ' demand ', ' price ', and ' cost ' # Output : a pandas DataFrame with columns ' scenario ', ' revenue ', ' profit ', and ' profit _ margin ' def simulate _ performance ( df ):
# Calculate the revenue for each scenario by multiplying the demand and price df [' revenue '] = df [' demand '] * df [' price ']
# Calculate the profit for each scenario by subtracting the cost from the revenue df [' profit '] = df [' revenue '] - df [' cost ']
Journal of Innovation 55