I replaced the "Country" values (includes South Korea) in Energy, but the autograder still shows " "South Korea" should be in the index of the energy DataFrame". May I ask why and how to fix it?
Energy = pd.read_excel('assets/Energy Indicators.xls', header=None, skiprows = 18, skipfooter = 38, na_values = [...], usecols = [2,3,4,5], names = ['Country', 'Energy Supply', 'Energy Supply per Capita', '% Renewable']) # Convert Energy Supply to gigajoules Energy['Energy Supply'] = Energy['Energy Supply'].apply(lambda x: x * 1000000) # Rename values in energy's countries di = {"Republic of Korea": "South Korea", "United States of America": "United States", "United Kingdom of Great Britain and Northern Ireland": "United Kingdom", "China, Hong Kong Special Administrative Region": "Hong Kong"} Energy.replace({"Country": di},inplace = True) # Remove parenthesis in country list Energy['Country'] = Energy['Country'].str.extract('(^[a-zA-Z]+)', expand=False) Energy = Energy.set_index(['Country']) https://stackoverflow.com/questions/65756478/need-help-for-replace-values-python January 17, 2021 at 09:35AM
没有评论:
发表评论