1

I have two dataframes, both with a column 'hotelCode' that is type string. I made sure to convert both columns to string beforehand.

The first dataframe, we'll call old_DF looks like so:

enter image description here

and the second dataframe new_DF looks like:

enter image description here

I have been trying to merge these unsuccessfully. I've tried

final_DF = new_DF.join(old_DF, on = 'hotelCode')

and get this error:

enter image description here

I've tried a variety of things: changing the index name, various merge/join/concat and just haven't been successful.

Ideally, I will have a new dataframe where you have columns [[hotelCode, oldDate, newDate]] under one roof.

  • 1
    I think you're having exactly the same problem found here: https://stackoverflow.com/questions/52373285/pandas-join-on-string-datatype. Does the `merge` solution work, though a `merge` will grow this DataFrame a lot. Do you need to merge on the index **and** hotelCode? or simply concat? – ALollz Jan 15 '20 at 21:30
  • 1
    can you show the output of `old_df.hotelCode.head()` and `new_df.hotelCode.head()`? – Max Power Jan 15 '20 at 21:30
  • 1
    you should ensure the columns have the same variable type before merging the dataframes. But I'm confused how a column with values like "ALFTBW" could possibly be an int64 type in one of your dataframes (hence my question above) – Max Power Jan 15 '20 at 21:32

1 Answers1

3
import pandas as pd

final_DF = pd.merge(old_DF, new_DF, on='hotelCode', how='outer')
James
  • 32,991
  • 4
  • 47
  • 70
High-Octane
  • 1,104
  • 5
  • 19