Description
import numpy as np
import pandas as pd
df_left = pd.DataFrame(index=["a", "b"])
df_right = pd.DataFrame({"x": ["a", "c"]})
pd.merge(df_left, df_right, left_index=True, right_on="x", how="left")
# x
# 0.0 a
# NaN b
Problem description
This is closely related to #28220 but deals with the values of the DataFrame
rather than the index itself. When left joining on an index and a column it looks like the value "b"
from the index of df_left
is somehow getting carried over to the column x
, but "a"
should be the only value in this column since it's the only one that matches the index from df_left
. This is happening on 0.25.1 and master, and has been a bug for some time according to #28220.
Expected Output
x
a a
b NaN
Output of pd.show_versions()
pandas : 0.25.1
numpy : 1.16.4
pytz : 2019.2
dateutil : 2.8.0
pip : 19.1.1
setuptools : 41.0.1
Cython : None
pytest : 5.0.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.7.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
Seems related to this issue: #17257