A veterinarian’s office stores all of their data on pets and their owners in two dataframes: pets and owners . The owners dataframe has the columns ‘id’, ‘first_name’, ‘last_name’ and ‘address’. The ‘pets’ dataframe has the columns id , name , owner_id , and type . If the office wanted to combine the two dataframes into one dataframe called pets_owners , what following code could work?
pets_owners = pd.merge(
pets,
owners.rename(columns = {‘id’:‘owner_id’})
)
this ↑ is woking
Hi! My first guess is that there is already a column named “id” in the pets dataframe, so either you can’t have two columns with the same name or maybe the merge function can’t combine the two dataframes if there are two columns with the same name in one of them.
This is because initially there’s no column named “id” in the owners dataframe and after renaming it the merge function is able to match it with the “id” column of the pets dataframe.
Why is it that when I add inplace=True to the .rename( ) method, the merged DataFrame won’t get printed out, whereas if I leave out inplace=True, it works just fine?