def get_country_code(x): return pycountry.countries.get(name=x).alpha_3 df = get_data('data.csv') df['Code'] = df['Country'].apply(get_country_code)