Search code examples
pythonmime-typessmtplib

how can we join two different tables where no common column is present using pandas


I have two tables one with offerid and other with emailid .I want both to be merged and come in a table.

import pandas as pd

data = pd.read_csv("offer1.txt")
data1 = pd.read_csv("offer2.txt")

print data.merge(data1, left_on='listid', right_on='profile/emailid', how='left')

I am getting output like this:

 listid                   profile/emailid
0    588001                            NaN

1    614001                            NaN

2       NaN                       rcruise295@yahoo.com

3       NaN                         2282377983

I want like this

 listid                   profile/emailid

  588001                 rcruise295@yahoo.com

  614001                   2282377983

can any on help me


Solution

  • From the output you specify, seems that you want to merge on index

    data.reset_index(drop=True, inplace=True)
    data1.reset_index(drop=True, inplace=True)
    data.merge(data1, left_index=True, right_index=True)