报错Traceback (most recent call last): File "E:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-37-e7a35394cf16>", line 6, in <module> Guangzhou_data = data.query('省 == "北京市" and 2000 <= 年份 <= 2019 月份 == 2').groupby(by='年份').mean() File "E:\Anaconda\lib\site-packages\pandas\core\frame.py", line 3231, in query res = self.eval(expr, **kwargs) File "E:\Anaconda\lib\site-packages\pandas\core\frame.py", line 3346, in eval return _eval(expr, inplace=inplace, **kwargs) File "E:\Anaconda\lib\site-packages\pandas\core\computation\eval.py", line 332, in eval parsed_expr = Expr(expr, engine=engine, parser=parser, env=env) File "E:\Anaconda\lib\site-packages\pandas\core\computation\expr.py", line 764, in __init__ self.terms = self.parse() File "E:\Anaconda\lib\site-packages\pandas\core\computation\expr.py", line 781, in parse return self._visitor.visit(self.expr) File "E:\Anaconda\lib\site-packages\pandas\core\computation\expr.py", line 371, in visit raise e File "E:\Anaconda\lib\site-packages\pandas\core\computation\expr.py", line 367, in visit node = ast.fix_missing_locations(ast.parse(clean)) File "E:\Anaconda\lib\ast.py", line 47, in parse return compile(source, filename, mode, flags, File "<unknown>", line 1 省 =="北京市"and 2000 <=年份 <=2019 月份 ==2 ^ SyntaxError: invalid syntax
时间: 2023-08-05 11:08:07 浏览: 212
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
根据报错信息,你的代码中存在语法错误,具体是在查询条件中出现了语法错误。检查后发现,查询条件中的语法错误是 `省 =="北京市"and 2000 <=年份 <=2019 月份 ==2`,其中缺少了 `and` 关键字,正确的写法应该是 `省 =="北京市" and 2000 <=年份 <=2019 and 月份 ==2`,需要在 `and` 后面添加两个空格,这样才能正确地识别出两个条件。
阅读全文