我正在尝试使用United States of America
函数将United States
替换为df.replace
。
我首先读取文件并更改了列名:
energy = (pd.read_excel("Energy Indicators.xls",
header = None, skiprows = 18, skipfooter=38,
usecols = [2,3,4,5],
names= ['Country', 'Energy Supply','Energy Supply per Capita', '% Renewable']))
接下来,我尝试使用以下脚本将United States of America
替换为United States
:
energy.replace("United States of America", "United States", inplace = True)
,但仍输出以下字符串“ United States of America”。当我键入其他国家/地区名称时,替换功能将起作用。