第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在pandas中使用country_converter將國(guó)家/地區(qū)代碼轉(zhuǎn)換為名稱(chēng)

如何在pandas中使用country_converter將國(guó)家/地區(qū)代碼轉(zhuǎn)換為名稱(chēng)

湖上湖 2023-09-05 17:21:37
df         Date        Value CODE0      2020-03-12      7  AFG1      2020-03-11      7  AFG...我如何從代碼生成國(guó)家/地區(qū)?我嘗試從 CODE 變量生成代碼import country_converter as cocodf['country'] = df['CODE'].apply(coco.convert)Actual Output:         Date        Value CODE  country0      2020-03-12      7  AFG     AFG  1      2020-03-11      7  AFG     AFG Expected Output:         Date        Value CODE  country0      2020-03-12      7  AFG     Afghanistan  1      2020-03-11      7  AFG     Afghanistan  
查看完整描述

1 回答

?
慕絲7291255

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)



查看完整回答
反對(duì) 回復(fù) 2023-09-05
  • 1 回答
  • 0 關(guān)注
  • 181 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)