0

I am trying to compare the following two tables. After comparing the words in table B with the words in table A, I want to put the code of the overlapping value in the empty Code column of table A. Since it is not case-sensitive, I want to change all words to lower case before proceeding with the comparison. If they don't match, I want to disable code injection.

There are about 10000 pieces of data

I haven't been able to solve this for 2 days. Please help me!!

Table A

Code Title
Cholera
Intestinal infection due to other Vibrio
Typhoid fever
Typhoid peritonitis
Paratyphoid fever
Infections due to other Salmonella
Salmonella enteritis

Table B

Code Title
1A00 Cholera
1A01 Intestinal infection due to other Vibrio
1A02 Intestinal infections due to Shigella
1A07 Typhoid fever
1A07.0 Typhoid peritonitis
1A07.Y Other specified typhoid fever
1A07.Z Typhoid fever, unspecifiedw

result Table

Code Title
1A00 Cholera
1A01 Intestinal infection due to other Vibrio
1A07 Typhoid fever
1A07.0 Typhoid peritonitis
Paratyphoid fever
Infections due to other Salmonella
Salmonella enteritis
이승우
  • 5
  • 2

1 Answers1

0

First create a new column with the lower case

then just do a standard merge

df3 = pd.merge(
    df1,
    df2,
    how = 'left',
    on = 'cat',
    suffixes = ['_x', '']
    )[['Code', 'Title_x']].rename(columns = {'Title_x': 'Title'})
Quixotic22
  • 2,894
  • 1
  • 6
  • 14