Merging two csv in Pandas and I get an empty column

Viewed 53

I am using this code to merge two csv files that are formatted like this:

buyer         product
<address>     <code>
<address>     <code>
<address>     <code>

and

product          seller
<code>        <address>
<code>        <address>
<code>        <address>
import pandas as pd


buyers = pd.read_csv("buyers.csv")
sellers = pd.read_csv("sellers.csv")

merged = pd.merge(buyers, sellers, on="product", how="outer")
merged.to_csv("merged.csv", index=False)

and my output csv looks like this:

buyer         product        seller
<address>     <code>
<address>     <code>
<address>     <code>

The last column is completely blank and I can't seem to figure out why. Is there something wrong with my input or am I going about this completely wrong? I am trying to put the two data sets together such that they merge where the code is the same.

1 Answers

I think there may be something going on with the underlying data, as the code seems to work as expected. Are you able to give us a sample?

Outside of that, I would double check that the product data type is the same across both dataframes.

buyers.dtypes
sellers.dtypes

dic1 = {'buyer':[13,23,53],'product':[1,2,3]}
dic2 = {'product':[1,2,3],'seller':['add1','add2','add3']}

buyer = pd.DataFrame(dic1)
seller = pd.DataFrame(dic2)

merged = pd.merge(buyer,seller,on='product',how='outer')
merged

My Output

Related