I am trying to combine four rows into two based on the name of the 'Country'. the dataframe is as follows (sorry for the bad format if there is a better way to show it please let me know):
(Index),Country,SPI_Score,WHR_Score
...............................
190,Congo Republic of,48.45, NaN
191,Congo Democratic Republic of,42.25, NaN
................................
198,Congo (Brazzaville), NaN ,5.194
199,Congo (Kinshasa), NaN ,4.311
My problem here is that when I did an outer join the countries had different names. I tried replacing the country names like this:
for i in range(len(df['Country'])):
if df.iloc[i]['Country'] in ['Congo Republic of', 'Congo (Brazzaville)']:
df.iloc[i]['Country'] = 'Republic of the Congo'
elif df[i]['Country'] in ['Congo Democratic Republic of', 'Congo (Kinshasa)']:
df.iloc[i]['Country'] = 'Democratic Republic of the Congo'
else:
continue
However this did not work and gave me the original df. The output that I want is:
(Index),Country,SPI_Score,WHR_Score
...............................
190,Republic of the Congo,48.45, 5.194
191,Democratic Republic of the Congo,42.25, 4.311