a) What is the main intent of this program - why would someone have written it? b)
Fantastic news! We've Found the answer you've been seeking!
Question:
a) What is the main intent of this program - why would someone have written it?
b) How might the output be relevant to the operation and management of Muesli AG?
Transcribed Image Text:
1 ### Run parameters ### 2 control = '2022-12-02' 2 import pyodbc 3 import pandas as pd 5 1 2 def some func(r): 3 4 6 7 8 9 # Import Libraries 14 15 16 1 # Function definitions 1 # SQL 2 sqlInv= f""" 3 select trim(Location Code) as Loc, trim(Material_Code) as Mat, Date, Quantity as Closing 4 from Inventory_Counts 5 where Date >= '{control}' and Location Code != '02' 6 order by Location_Code, Material_Code, Date 7 2 8 9 sqlSales = f""" 10 select trim(si.Material_Code) as Mat, c. Region, so.Delivery_Date as Date, sum(si.Quantity) as Sold from Sales Order_Items si 11 12 13 if r in ['01', '62', '63', '64', '11', '12', '13', '14', '15']: return '02N' elif r in ['06', '08', '09', '16']: return '025' ****** elif r in ['05', '07', '10']: return '02W" else: return None. 33 34 inner join Sales_Orders so on so. Doc_Number = si.Doc_Number inner join Customers c on c. Customer_ID = so. Customer_ID where Delivery_Date> '{control}' group by c. Region, si.Material_Code, so.Delivery_Date # Main program cxn = pyodbc.connect("DRIVER={SQL Server}; SERVER=dlyle.database.windows.net; DATABASE=MuesliAG; UID-student; PWD=Viz (Data)") 3 4 dfSales = pd. read_sql (sqlSales, cxn, parse_dates = 'Date') 5 dfSales ['Loc'] = dfSales. Region.apply(some_func) 6 dfSales = dfSales.groupby(['Loc', 'Mat', 'Date']).sum().reset_index() 7 8 dfInv = pd.read_sql(sqlInv, cxn, parse_dates = 'Date') 9 10 varl 11 var2 = 12 for r in dfInv.itertuples(): 13 14 if dfInv.loc [r. Index, 'Loc'] == var1 and dfInv. loc [r. Index, 'Mat'] == var2: df Inv. loc [r. Index, 'Opening'] = dfInv.loc [r.Index-1, Closing'] else: 15 16 17 18 19 data pd.merge( 20 11 = var1 = dfInv.loc [r. Index, 'Loc'] var2 = dfInv.loc [r. Index, 'Mat'] df Inv [dfInv.Date > control], dfSales, 21 22 23 ).fillna (0) 24 25 dfMean = data[(data.Sold < data.Opening) & (data.Sold > 0)].groupby(['Loc', 'Mat']).Sold.mean() 26 data pd.merge( 27 28 = how="left', on=['Loc', 'Mat', 'Date'] data, dfMean, how="left', on=['Loc', 'Mat'], suffixes=[None, '_Mean'] 29 30 ) 31 32 dfout = ( data[ (data.Opening >= data.Sold_Mean) & (data.Sold_Mean > 0)].groupby(['Loc', 'Mat']). Date.count() /data.groupby(['Loc', 'Mat']).Date.count() 35 ) 36 dfout = pd.merge( 37 dfout, 38 dfMean, 39 how- 'outer', on=['Loc', 'Mat'] 40 ).fillna (0) 1 # Output 2 dfout.to_csv('output.csv', index_label=['Location', 'Material_Code'], header=['KPI1', 'KPI2']) 1 ### Run parameters ### 2 control = '2022-12-02' 2 import pyodbc 3 import pandas as pd 5 1 2 def some func(r): 3 4 6 7 8 9 # Import Libraries 14 15 16 1 # Function definitions 1 # SQL 2 sqlInv= f""" 3 select trim(Location Code) as Loc, trim(Material_Code) as Mat, Date, Quantity as Closing 4 from Inventory_Counts 5 where Date >= '{control}' and Location Code != '02' 6 order by Location_Code, Material_Code, Date 7 2 8 9 sqlSales = f""" 10 select trim(si.Material_Code) as Mat, c. Region, so.Delivery_Date as Date, sum(si.Quantity) as Sold from Sales Order_Items si 11 12 13 if r in ['01', '62', '63', '64', '11', '12', '13', '14', '15']: return '02N' elif r in ['06', '08', '09', '16']: return '025' ****** elif r in ['05', '07', '10']: return '02W" else: return None. 33 34 inner join Sales_Orders so on so. Doc_Number = si.Doc_Number inner join Customers c on c. Customer_ID = so. Customer_ID where Delivery_Date> '{control}' group by c. Region, si.Material_Code, so.Delivery_Date # Main program cxn = pyodbc.connect("DRIVER={SQL Server}; SERVER=dlyle.database.windows.net; DATABASE=MuesliAG; UID-student; PWD=Viz (Data)") 3 4 dfSales = pd. read_sql (sqlSales, cxn, parse_dates = 'Date') 5 dfSales ['Loc'] = dfSales. Region.apply(some_func) 6 dfSales = dfSales.groupby(['Loc', 'Mat', 'Date']).sum().reset_index() 7 8 dfInv = pd.read_sql(sqlInv, cxn, parse_dates = 'Date') 9 10 varl 11 var2 = 12 for r in dfInv.itertuples(): 13 14 if dfInv.loc [r. Index, 'Loc'] == var1 and dfInv. loc [r. Index, 'Mat'] == var2: df Inv. loc [r. Index, 'Opening'] = dfInv.loc [r.Index-1, Closing'] else: 15 16 17 18 19 data pd.merge( 20 11 = var1 = dfInv.loc [r. Index, 'Loc'] var2 = dfInv.loc [r. Index, 'Mat'] df Inv [dfInv.Date > control], dfSales, 21 22 23 ).fillna (0) 24 25 dfMean = data[(data.Sold < data.Opening) & (data.Sold > 0)].groupby(['Loc', 'Mat']).Sold.mean() 26 data pd.merge( 27 28 = how="left', on=['Loc', 'Mat', 'Date'] data, dfMean, how="left', on=['Loc', 'Mat'], suffixes=[None, '_Mean'] 29 30 ) 31 32 dfout = ( data[ (data.Opening >= data.Sold_Mean) & (data.Sold_Mean > 0)].groupby(['Loc', 'Mat']). Date.count() /data.groupby(['Loc', 'Mat']).Date.count() 35 ) 36 dfout = pd.merge( 37 dfout, 38 dfMean, 39 how- 'outer', on=['Loc', 'Mat'] 40 ).fillna (0) 1 # Output 2 dfout.to_csv('output.csv', index_label=['Location', 'Material_Code'], header=['KPI1', 'KPI2'])
Expert Answer:
Answer rating: 100% (QA)
The main intent of this program appears to be performing data analysis and processing tasks on two data sources likely related to a business or organizations inventory and sales data Here are the key ... View the full answer
Related Book For
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood
Posted Date:
Students also viewed these programming questions
-
According to Planck's law of black- body radiation, the spectral energy density R as a function of wavelength (m) and temperature 7 (K) is given by: 2ch 1 R = 15 he/NkT -1 where c=3108 m/s is the...
-
Carol Harris, Ph.D, CPA, is a single taxpayer and she lives at 674 Yankee Street, Durham, NC 27409. Her Social Security number is 793-52-4335. Carol is an Associate Professor of Accounting at a local...
-
What is the spring cloud API Gateway and how do you set it up to make a call to the product service via eureka service discovery server? Give me the complete code in detailed steps.
-
Administrative agencies, boards or commissions usually use registration or licensing to control business subject to the administrative law. True False
-
A 0.7-lb block rests on top of a 0.5-lb block supported by but not attached to a spring of constant 9 lb/ft. The upper block is suddenly removed. Determine (a) The maximum velocity reached by the...
-
Maynard Corporation buys 1,000 call options to buy 1,000 shares of Rossman, Inc., common stock on December 1, 20X1. At the time of the purchase, the option price is $5.00, the Rossman stock price is...
-
Assume you work for an accounting firm and you are part of a team that does work for two clients that are competitors. Describe some ways in which ethical considerations might be an important part of...
-
The U.S. Census bureau serves as the leading source of quantitative data about the nation's people and economy. The following cross tabulation shows the number of households (1000s) and the household...
-
A company is expected to pay its first dividend in the amount of $2 a share 7 years from today. The dividend in year 8 will be $2.25 a share and the dividend in year 9 will be $2.50 a share, after...
-
Why is there a trend toward giving an increasing fraction of chip area to cache memory?
-
Determine how many LARGER 1.5 oz. drinks can be served from a 1.14 Liter bottle.Remember1 fl. oz. 28.41 ml .and 1 ml. = 0.0352 oz
-
adam likes to skateboard on a street that drops 8 5 . 9 ft over a horizontal distance of 5 0 4 ft . what is the grade of the street?
-
Rose' investment portfolio fell by 40% in the first year but rebounded by 40% in the second year. Did rose regain all of the money that she lost first year at end of the second year? If no explain why
-
Consider the singularly perturbed system x' = x+z z' = 2x^3z (a) Compute the quasi-steady-state system (b) Compute the boundary-layer system
-
4. [5 points] Find, if possible, the matrix X that satisfies the equation: -13 X +8 3
-
find all pair of positive integral a and b with a smaller than b such that a 2 + b 2 = 1 4 5 . use gaussian integers
-
4. Which of the following is not true about barter? a. It involves the direct exchange of one good or service for another. b. It is more likely to occur if people lose faith in a nation's currency....
-
Define the term utility software and give two examples.
-
Excel Assignment: Asset Retirement Scenarios Molly Company plans to retire its primary production facility in 30 years. The company is considering the establishment of a retirement account that will...
-
The Wadswad Corporation manufactures both standard and customized electrical control boards for automated manufacturing machinery. The company was started by an electrical engineer and a salesman for...
-
All business processes have at least three common components: a starting point, an ending point, and a triggering event. For each business process below, give all three components. a. Customer order...
-
Mike's Veneer Shop owns a vacuum press that requires annual maintenance. Mike has a contract to cover the maintenance expenses for the next 5 years. The contract calls for an annual payment of \(\$...
-
Give four examples of goods or services that have exhibited inflation in recent years.
-
What is the numeric value of the present worth of the original project (i.e., no changes)? a. -10 b. 20 c. 1,000 d. Cannot be determined from the information given
Study smarter with the SolutionInn App