1 回答

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
根據(jù)country_converter文檔。
to
和參數(shù)的有效值src
可以通過(guò) 找到coco.CountryConverter().valid_class
。
import country_converter as coco
import pandas as pd
# setupt test dataframe
df = pd.DataFrame({'code': ['AFG', 'USA', 'RU']})
# add country name by applying the convert method
df['short name'] = df.code.apply(lambda x: coco.convert(names=x, to='name_short', not_found=None))
# display(df)
? code? ? ?short name
0? AFG? ? Afghanistan
1? USA? United States
2? ?RU? ? ? ? ?Russia
# converting the column to a list and passing it to the method also works to add the short name
df['short name'] = coco.convert(names=df.code.tolist(), to='name_short', not_found=None)
添加回答
舉報(bào)