Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want to have the python code adjusted so it will read df2 and df5 and write to

ID: 3916098 • Letter: I

Question




I want to have the python code adjusted so it will read df2 and df5 and write to an excel file as indicated above. Thanks. using pandas with python to write to a dataframe d2 is dataframe 2 O Jobitte Department TrueDepartment Dept Function CMI-General Liability 1 85-9362 Central Operations Alarm Central 85-8642 Market 466 Talent, Experience Food Division Quality MCC Modular Execution Team 1 1-9700 US Central Operations CE Engineering Us Fresh, Freezer& Cooler 18-811 9701 Contact Center Central Operations US Central Operations Private Brands GH- 1-8683 df5 is dataframe5 Dept Nor Dept Desc_good Dept _Desc better Dept Abrv TRUCKING, MARCY, NY E, TN DC 48, HOPE MILLS,NC TRUCKING, SHARON SPRINGS DISP PAULS VALLEY OK FDC COLDWATER, MI AMERICOLD LOGISTICS DFW3N FORT WORTH FC - WHS.COM PCCC CURRENTLY BEING REVIEWED Springfield, MO Fresh Dept Security General Merchandise General Liability Execution Team Produce TN 466 8110 8642 8683 9362 9700 9701 Security&Compliance; Desired result after running code JobTitte Department TrueDepartnent CM?-General Liability las-9362 General Liability Central Operations Alarm Central 85-8642 Market 466 Talent, Experience Food Division Quality WHCC Hodutar Execut ion Team 1 1-9700 Execution Tean US Centra: 0peratins CE Engineering- US Fresh, Freezer & Cooler-18-8110 Fresh Dept Security &Compliance;

Explanation / Answer

Answer: The problem statement can be simplified as reading fro 2 different data frames and and write to an excel file after transforming the data as ead from the data frames. The out put should be appended as :

From df2 extract the job title , department and from df5 the value of dept_desc_better ( if available ) or the value of dept_desc_good ( if the value of dept_desc_better is NIL) for the corresponding dept_nbr form the department value as extracted from df2.

Please find the correct code snippet as below:

numbers = df5['Dept_Nbr'].tolist()

df5['Dept_Nbr'] = [int(i) for i in df5['Dept_Nbr']]

df5.set_index('Dept_Nbr')

for n in numbers:

    for i in df2.index:

        if n in df2.at[i, 'Department']:

            if df5.at[int(n), 'Dept_Desc_better']: #if values exists

                df2.at[i, 'TrueDepartment'] = df5.at(int(n), 'Dept_Desc_better')

            else:

                df2.at[i, 'TrueDepartment'] = df5.at(int(n), 'Dept_Desc_good')

                                        

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote