2

I have two csv files, which have different rows in them

For example, A csv, has 2000 rows, while B csv, has 100.000 rows, and i need to check,
How could i alter the following code, for the following task?

I need to lookup, all serial numbers from the first csv, and find matches, on the second csv. The result report, will have the serial number that matched, and the corresponding product ids from each csv, in a separate column:

A = pd.DataFrame({'product id':   [1455,5452,3775],
                    'serial number':[44,55,66]})

print (A)

B = pd.DataFrame({'product id':   [7000,2000,1000],
                    'serial number':[44,55,77]})

print (B)

print (pd.merge(A, B, on='serial number'))

Desired output:

product id_x  serial number  product id_y
   1455             44          7000
   5452             55          2000
3
  • 1
    What is desired output? Can yo add it to question? Commented Feb 24, 2017 at 11:50
  • 3
    The code you posted has little relevance to your real problem, you need to load the data using read_csv, you then need to perform a left type merge so pd.merge(A,B, on='serial_number', how='left') Commented Feb 24, 2017 at 11:50
  • @ jezrael :) stackoverflow.com/a/42418610/6626530 Commented Feb 24, 2017 at 13:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.