Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with Pandas Data frame and a running python code without error Output Table Problem: Given two data frames, df1 and df2. Compare the

Need help with Pandas Data frame and a running python code without error

image text in transcribed

image text in transcribed

Output Table

image text in transcribed

Problem: Given two data frames, df1 and df2. Compare the values in the LOC column in both data frames. If there is a difference in the same index number in both data frames while comparing, there will be a new table called DF3. The new table will merge the columns from both data frames and create two additional columns, TY and RC. TY column has three values 'Base', 'Comp', and ' Dif '. 'Base' refers to the DF1 data frame, 'Comp' refers to the DF2 data frame, and 'Dif ' refers to the difference between data frames(DF1 & DF2). Rec column refers to the index number/observation for LOC column values in which the column value doesnt match.

For example, DF1 and DF2 data frame has column LOC .If in the second record,DF1 has INY value and DF2 have sju value, in the new table column LOC would get 3 values like INY, sju and xxx. So Iny, sju & xxx will connect with respectively Base, comp & Dif under the TY column.

If there is no data in Loc column in DF1/DF2, then it will be empty in the DF3 table column(LOC). We dont have to add Dif in the TY column and xxx in the Loc column in the new table.

DF1 \begin{tabular}{|l|l|l|l|l|} \hline & P & C & S & Loc \\ \hline 1 & 120 & IN & arw & law \\ \hline 2 & 121 & US & arw & Iny \\ \hline 3 & 122 & CA & arw & \\ \hline 4 & 123 & US & arw & sju \\ \hline 5 & 124 & US & fx & sju \\ \hline 6 & 125 & US & fx & Iny \\ \hline \end{tabular} +DF2 \begin{tabular}{|l|l|l|l|l|} \hline & P & C & S & Loc \\ \hline 1 & 120 & IN & arw & law \\ \hline 2 & 121 & US & arw & sju \\ \hline 3 & 122 & CA & arw & sju \\ \hline 4 & 123 & US & arw & sju \\ \hline 5 & 124 & US & fx & sju \\ \hline 6 & 125 & US & fx & \\ \hline \end{tabular} DF3 \begin{tabular}{|l|l|l|l|l|l|} \hline TY & Rec & p & c & s & Loc \\ \hline Base & 2 & 121 & US & arw & Iny \\ \hline Comp & 2 & 121 & US & arw & sju \\ \hline Dif & 2 & 121 & US & arw & xxx \\ \hline Base & 3 & 122 & US & arw & \\ \hline Comp & 3 & 122 & US & arw & sju \\ \hline \end{tabular}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

=+5. How can you show them their personal benefits?

Answered: 1 week ago

Question

=+7. How does it enhance their lifestyle?

Answered: 1 week ago