Unable To Join Pandas Dataframe On String Type
I have two DataFrames objects whose columns are as below Dataframe 1: df.dtypes Output: ImageID object Source object LabelName object Confidence int64 dtype
Solution 1:
About the on
parameter, the documentation says:
Column or index level name(s) in the caller to join on the index in other, otherwise joins index-on-index.
Note that join()
always uses other.index
. You can try this:
df.join(a.set_index('LabelName'), on='LabelName')
Or use df.merge()
instead.
Solution 2:
There is problem some columns are integers along with string in DataFrame1 while all are strings in DataFrame2 which is causing the problem.
Simplest solution is cast all columns to strings:
pd.merge(df1.astype(str),df2.astype(str), how='outer')
As the Value Error suggesting itself use concat:
pd.concat([df1, df2])
Solution 3:
Try converting the Confidence column to an object first because there is a dtype mismatch.
df['Confidence'].apply(str)
Post a Comment for "Unable To Join Pandas Dataframe On String Type"