I'm trying to replace some string values in an index column in a pandas data frame. The indexes are country names, and I want to replace strings like 'United Kingdom of England and Northern Ireland' with 'UK'.
The data framelooks like this:
data = ['12','13','14', '15']
df = pd.DataFrame(data, index = ['Republic of Korea','United States of America20', 'United Kingdom of Great Britain and Northern Ireland19','China, Hong Kong Special Administrative Region'],columns=['Country'])
I have tried:
d={"Republic of Korea": "South Korea",
"United States of America20": "United States",
"United Kingdom of Great Britain and Northern Ireland19": "United Kingdom",
"China, Hong Kong Special Administrative Region": "Hong Kong"}
df.index = df.index.str.replace(d)
Unfortunately, I just get an error message that replace is missing a positional argument.