def merge_breed_name_sub(train):
    breeds = pd.read_csv('../input/petfinder-adoption-prediction/breed_labels.csv')
    df = pd.read_json('../input/cat-and-dog-breeds-parameters/rating.json')
    cat_df = df.cat_breeds.dropna(0).reset_index().rename(columns={'index': 'BreedName'})
    dog_df = df.dog_breeds.dropna(0).reset_index().rename(columns={'index': 'BreedName'})
    cat = cat_df['cat_breeds'].apply((lambda x: pd.Series(x)))
    cat_df = pd.concat([cat_df, cat], axis=1).drop(['cat_breeds'], axis=1)
    dog = dog_df['dog_breeds'].apply((lambda x: pd.Series(x)))
    dog_df = pd.concat([dog_df, cat], axis=1).drop(['dog_breeds'], axis=1)
    df = pd.concat([dog_df, cat_df])
    df.BreedName.replace({'Siamese Cat': 'Siamese', 'Chinese Crested': 'Chinese Crested Dog', 'Australian Cattle Dog': 'Australian Cattle Dog/Blue Heeler', 'Yorkshire Terrier': 'Yorkshire Terrier Yorkie', 'Pembroke Welsh Corgi': 'Welsh Corgi', 'Sphynx': 'Sphynx (hairless cat)', 'Plott': 'Plott Hound', 'Korean Jindo Dog': 'Jindo', 'Anatolian Shepherd Dog': 'Anatolian Shepherd', 'Belgian Malinois': 'Belgian Shepherd Malinois', 'Belgian Sheepdog': 'Belgian Shepherd Dog Sheepdog', 'Belgian Tervuren': 'Belgian Shepherd Tervuren', 'Bengal Cats': 'Bengal', 'Bouvier des Flandres': 'Bouvier des Flanders', 'Brittany': 'Brittany Spaniel', 'Caucasian Shepherd Dog': 'Caucasian Sheepdog (Caucasian Ovtcharka)', 'Dandie Dinmont Terrier': 'Dandi Dinmont Terrier', 'Bulldog': 'English Bulldog', 'American English Coonhound': 'English Coonhound', 'Small Munsterlander Pointer': 'Munsterlander', 'Entlebucher Mountain Dog': 'Entlebucher', 'Exotic': 'Exotic Shorthair', 'Flat-Coated Retriever': 'Flat-coated Retriever', 'English Foxhound': 'Foxhound', 'Alaskan Klee Kai': 'Klee Kai', 'Newfoundland': 'Newfoundland Dog', 'Norwegian Forest': 'Norwegian Forest Cat', 'Nova Scotia Duck Tolling Retriever': 'Nova Scotia Duck-Tolling Retriever', 'American Pit Bull Terrier': 'Pit Bull Terrier', 'Ragdoll Cats': 'Ragdoll', 'Standard Schnauzer': 'Schnauzer', 'Scottish Terrier': 'Scottish Terrier Scottie', 'Chinese Shar-Pei': 'Shar Pei', 'Shetland Sheepdog': 'Shetland Sheepdog Sheltie', 'West Highland White Terrier': 'West Highland White Terrier Westie', 'Soft Coated Wheaten Terrier': 'Wheaten Terrier', 'Wirehaired Pointing Griffon': 'Wire-haired Pointing Griffon', 'Xoloitzcuintli': 'Wirehaired Terrier', 'Cane Corso': 'Cane Corso Mastiff', 'Havana Brown': 'Havana'}, inplace=True)
    breeds = breeds.merge(df, how='left', on='BreedName')
    train = train.merge(breeds.rename(columns={'BreedName': 'BreedName_main_breed'}), how='left', left_on='Breed1', right_on='BreedID', suffixes=('', '_main_breed'))
    train.drop(['BreedID'], axis=1, inplace=True)
    train = train.merge(breeds.rename(columns={'BreedName': 'BreedName_second_breed'}), how='left', left_on='Breed2', right_on='BreedID', suffixes=('', '_second_breed'))
    train.drop(['BreedID'], axis=1, inplace=True)
    return train
def merge_breed_name_sub(train):
    breeds = pd.read_csv('../input/petfinder-adoption-prediction/breed_labels.csv')
    df = pd.read_json('../input/cat-and-dog-breeds-parameters/rating.json')
    cat_df = df.cat_breeds.dropna(0).reset_index().rename(columns={'index': 'BreedName'})
    dog_df = df.dog_breeds.dropna(0).reset_index().rename(columns={'index': 'BreedName'})
    cat = cat_df['cat_breeds'].apply((lambda x: pd.Series(x)))
    cat_df = pd.concat([cat_df, cat], axis=1).drop(['cat_breeds'], axis=1)
    dog = dog_df['dog_breeds'].apply((lambda x: pd.Series(x)))
    dog_df = pd.concat([dog_df, cat], axis=1).drop(['dog_breeds'], axis=1)
    df = pd.concat([dog_df, cat_df])
    df.BreedName.replace({'Siamese Cat': 'Siamese', 'Chinese Crested': 'Chinese Crested Dog', 'Australian Cattle Dog': 'Australian Cattle Dog/Blue Heeler', 'Yorkshire Terrier': 'Yorkshire Terrier Yorkie', 'Pembroke Welsh Corgi': 'Welsh Corgi', 'Sphynx': 'Sphynx (hairless cat)', 'Plott': 'Plott Hound', 'Korean Jindo Dog': 'Jindo', 'Anatolian Shepherd Dog': 'Anatolian Shepherd', 'Belgian Malinois': 'Belgian Shepherd Malinois', 'Belgian Sheepdog': 'Belgian Shepherd Dog Sheepdog', 'Belgian Tervuren': 'Belgian Shepherd Tervuren', 'Bengal Cats': 'Bengal', 'Bouvier des Flandres': 'Bouvier des Flanders', 'Brittany': 'Brittany Spaniel', 'Caucasian Shepherd Dog': 'Caucasian Sheepdog (Caucasian Ovtcharka)', 'Dandie Dinmont Terrier': 'Dandi Dinmont Terrier', 'Bulldog': 'English Bulldog', 'American English Coonhound': 'English Coonhound', 'Small Munsterlander Pointer': 'Munsterlander', 'Entlebucher Mountain Dog': 'Entlebucher', 'Exotic': 'Exotic Shorthair', 'Flat-Coated Retriever': 'Flat-coated Retriever', 'English Foxhound': 'Foxhound', 'Alaskan Klee Kai': 'Klee Kai', 'Newfoundland': 'Newfoundland Dog', 'Norwegian Forest': 'Norwegian Forest Cat', 'Nova Scotia Duck Tolling Retriever': 'Nova Scotia Duck-Tolling Retriever', 'American Pit Bull Terrier': 'Pit Bull Terrier', 'Ragdoll Cats': 'Ragdoll', 'Standard Schnauzer': 'Schnauzer', 'Scottish Terrier': 'Scottish Terrier Scottie', 'Chinese Shar-Pei': 'Shar Pei', 'Shetland Sheepdog': 'Shetland Sheepdog Sheltie', 'West Highland White Terrier': 'West Highland White Terrier Westie', 'Soft Coated Wheaten Terrier': 'Wheaten Terrier', 'Wirehaired Pointing Griffon': 'Wire-haired Pointing Griffon', 'Xoloitzcuintli': 'Wirehaired Terrier', 'Cane Corso': 'Cane Corso Mastiff', 'Havana Brown': 'Havana'}, inplace=True)
    breeds = breeds.merge(df, how='left', on='BreedName')
    train = train.merge(breeds.rename(columns={'BreedName': 'BreedName_main_breed'}), how='left', left_on='Breed1', right_on='BreedID', suffixes=(, '_main_breed'))
    train.drop(['BreedID'], axis=1, inplace=True)
    train = train.merge(breeds.rename(columns={'BreedName': 'BreedName_second_breed'}), how='left', left_on='Breed2', right_on='BreedID', suffixes=(, '_second_breed'))
    train.drop(['BreedID'], axis=1, inplace=True)
    return train