Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python语法错误-遵循给定的示例,无法找出错误所在_Python_Python 3.x_Dictionary_Syntax Error - Fatal编程技术网

Python语法错误-遵循给定的示例,无法找出错误所在

Python语法错误-遵循给定的示例,无法找出错误所在,python,python-3.x,dictionary,syntax-error,Python,Python 3.x,Dictionary,Syntax Error,我目前正在做学徒,学习使用python 3 我将按照提供的说明/演练进行一些练习 尝试更改列名时,我开始出现以下错误: File "<ipython-input-25-591a166ee92a>", line 5 'human development index (male)':"hdi_m" ^ SyntaxError: invalid syntax 有什么想法

我目前正在做学徒,学习使用python 3

我将按照提供的说明/演练进行一些练习

尝试更改列名时,我开始出现以下错误:

File "<ipython-input-25-591a166ee92a>", line 5
    'human development index (male)':"hdi_m"
                                    ^
SyntaxError: invalid syntax

有什么想法吗?

看起来您缺少了几个逗号,在python字典中,它们在键值对之间分开。请注意以下代码中的附加逗号:

gender_development.rename(columns={'gdi rank': "gdi_rank",
                               'gender development index (gdi)': "gdi",
                               'human development index (male)': "hdi_m",
                               'life expectancy at birth (female)': "life_expectancy_f",
                               'life expectancy at birth (male)': "life_expectancy_m",
                               'expected years of educaton (female)':"expected_education_years_f",
                               'expected years of education (male)': "expected_education_years_m",
                               'mean years of education (female)':"mean_education_years_f",
                               'mean years of education (male)': "mean_education_years_m",
                               'estimated gross national income per capita (female)':"gross_income_pc_f",
                               'estimated gross national income per capita (male)': "gross_income_pc_m",
                               'human development index (female)':"hdi_f"}, inplace = True)

所有编程语言都对这种语法错误非常敏感。试着注意使用正确的结构——随着时间的推移,这对你来说会变得很自然。

另外,试着用一根短绒。短绒会(可能)抱怨,线条长度超过80个字符,缩进不足,视觉上缺乏缩进,在:,之后缺乏空间,等等

清除所需的所有错误(缺少的性别发展除外):

gender_development.rename(columns={
    'gdi rank': "gdi_rank",
    'gender development index (gdi)': "gdi",
    'human development index (male)': "hdi_m",
    'life expectancy at birth (female)': "life_expectancy_f",
    'life expectancy at birth (male)': "life_expectancy_m",
    'expected years of educaton (female)': "expected_education_years_f",
    'expected years of education (male)': "expected_education_years_m",
    'mean years of education (female)': "mean_education_years_f",
    'mean years of education (male)': "mean_education_years_m",
    'estimated gross national income per capita (female)': "gross_income_pc_f",
    'estimated gross national income per capita (male)': "gross_income_pc_m",
    'human development index (female)': "hdi_f"
}, inplace=True)

你需要在每一行的末尾加逗号。谢谢!我一直在努力寻找大错误,忘记小错误。我最终会到达那里的。
gender_development.rename(columns={
    'gdi rank': "gdi_rank",
    'gender development index (gdi)': "gdi",
    'human development index (male)': "hdi_m",
    'life expectancy at birth (female)': "life_expectancy_f",
    'life expectancy at birth (male)': "life_expectancy_m",
    'expected years of educaton (female)': "expected_education_years_f",
    'expected years of education (male)': "expected_education_years_m",
    'mean years of education (female)': "mean_education_years_f",
    'mean years of education (male)': "mean_education_years_m",
    'estimated gross national income per capita (female)': "gross_income_pc_f",
    'estimated gross national income per capita (male)': "gross_income_pc_m",
    'human development index (female)': "hdi_f"
}, inplace=True)