I use pd.merge to link two excel, but it returns empty dataFrame
#
df1 = pd.read_excel('gz.xlsx')
df2 = pd.read_excel('dyml.xlsx')
pd.merge(df1, df2, on = 'name')
df1 and df2 have the same data in column name,but it can't merge
Output of Empty DataFrame
Comment From: bkandel
Without a reproducible example it's hard to tell what's going on here. Once the dataframes are read in from Excel they are normal dataframes -- the fact that they originated from an Excel workbook doesn't matter. If you could post the content of the two dataframes and what the output of the merge
is it would help debugging.
Comment From: miaoxu9999
@bkandel thanks for your reply ,below are my data .could you help me solve the problem?
Comment From: GeraintDuck
The names column in c.xlsx has extra white-space surrounding the text.
Try something like:
df1 = pd.read_excel('c.xlsx')
df1['name'] = df1['name'].str.strip()
df2 = pd.read_excel('t.xlsx')
df2['name'] = df2['name'].str.strip()
pd.merge(df1, df2, on='name')
Note that the default merge is an inner join too.
Comment From: jorisvandenbossche
@miaoxu9999 The github issues are meant for reporting issues that possibly are bugs, not for general questions and answers. For this, StackOverflow or the mailing list is a better place to ask (but of course, the line between both is not always clear)