-1

I have two csv files.

One that has columns that look like this:

10.10.10.10 madeupdnsentry.domain.com

and the other looks like this:

10.10.10.10 ABCD.EFGH.1234

I'd like to compare and combine the entries that match. So I could end up with:

10.10.10.10 madeupdnsentry.domain.com ABCD.EFGH.1234

What would be the best way to do that? It has about 1000 entries some will have matches some won't. Any help is appreciated.

Dan
  • 359
  • 5
  • 17
  • Possible duplicate of [Merging 2 csv files](https://stackoverflow.com/questions/16265831/merging-2-csv-files) – Mr. T Feb 07 '18 at 17:21

2 Answers2

0

You could read in the csv files with Pandas using pandas.read_csv(path), and then use the .merge() function in pandas to join them on whichever column you would like, and can set how the join is done by passing the parameter how, for example df1.merge(df2, on='some_column', how='left')

Blazina
  • 1,206
  • 10
  • 13
0

Using pandas. Note that this is essentially doing an inner join so if there are unmatched records between the two data sets they will fall out. But you can change the join using the how keyword argument in the merge function.

>>> import pandas as pd
>>> data1 = [['10.10.10.10','madeupdnsentry.domain.com']] 
>>> data2 = [['10.10.10.10','ABCD.EFGH.1234']]
>>> df1 = pd.DataFrame(data1, columns=['ip', 'domain1'])
>>> df2 = pd.DataFrame(data2, columns=['ip', 'domain2'])
>>> df1.merge(df2, on='ip')
            ip                    domain1         domain2
0  10.10.10.10  madeupdnsentry.domain.com  ABCD.EFGH.1234
Orenshi
  • 1,773
  • 11
  • 12