申し訳ありませんが、NOOBはここにあります! DataFrameのインデックス列の一部の文字列値を置換しようとしています。インデックスは国名であり、「英国と北アイルランド」のようなものを「英国」に置き換える必要があります。PythonのDataFrameインデックス値を条件付き引数に置き換える
は、データフレームは以下のようになります。私は試してみました
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'])
:私は確かにその非常に簡単だし、それを実行する方法のために広範囲に検索しました
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)
。 replaceが位置引数を欠いているというエラーメッセージを取得するだけです。
'pd.Series(df.index.values).replace(d)'をあなたのタイムリストにも追加できますか? –
もちろん、問題ありません。完了しました。 – jezrael