简体   繁体   English

运行 Python 代码时的另一个回溯错误

[英]Another Traceback Error When I Run My Python Code

I have a new Traceback Error When, I run my Python Code.我有一个新的回溯错误,当我运行我的 Python 代码时。 It appears to be to do with the very last ) Parentheses, also maybe the last ] in my Code.它似乎与最后一个 ) 括号有关,也可能是我代码中的最后一个 ]。

((df['Location'].str.contains('- Display')) & 
                df['Lancaster'] != 'L' & 
                df['Dakota'] == 'D' & 
                df['Spitfire'] == 'SS' &
                df['Hurricane'] != 'H'))
              )]      

And here is the Traceback Error I get :这是我得到的回溯错误:

        File "<ipython-input-5-6d53e7e5ec10>", line 31
        )
        ^
    SyntaxError: invalid syntax  

Here is my latest, whole Code John S, that works.这是我最新的完整代码 John S,它有效。 I will let you know, if I get more issues, many thanks for your help :如果我遇到更多问题,我会通知您,非常感谢您的帮助:

import pandas as pd import requests from bs4 import BeautifulSoup

res = requests.get("http://web.archive.org/web/20070701133815/http://www.bbmf.co.uk/june07.html")
soup = BeautifulSoup(res.content,'lxml')
table = soup.find_all('table')[0]

df = pd.read_html(str(table))
df = df[1]
df = df.rename(columns=df.iloc[0])
df = df.iloc[2:]
df.head(15)

display = df[(df['Location'].str.contains('- Display')) & (df['Dakota'].str.contains('D')) & (df['Spitfire'].str.contains('S')) & (df['Lancaster'] != 'L')]     
display </code>

You just have to many brackets你只需要很多括号

((df['Location'].str.contains('- Display') & 
  df['Lancaster'] == '' & 
  df['Dakota'] == 'D' & 
  df['Spitfire'] == 'SS' & 
  df['Hurricane'] == ''))

You needed to remove a ')' after each ('- Display') it looks like you will still have some problems with sorting through your data.您需要在每个 ('- Display') 之后删除一个 ')' 看起来您在对数据进行排序时仍然会遇到一些问题。 But this should get you past your syntax error.但这应该可以让您克服语法错误。

Look at this online version so see my edits.看看这个在线版本,看看我的编辑。

https://onlinegdb.com/Skceaucyr https://onlinegdb.com/Skceaucyr

you need to add ")]" in the end.您需要在最后添加“)]”。 So you variable southport will be now所以你可变的南港现在将是

Southport = df[
    (
        ((df['Location'].str.contains('- Display') & 
        df['Lancaster'] != 'L' & 
        df['Dakota'] == 'D' & 
        df['Spitfire'] == 'S' & 
        df['Hurricane'] == 'H'))
    )
] | df[
    (
        ((df['Location'].str.contains('- Display') & 
        df['Lancaster'] != 'L' & 
        df['Dakota'] == 'D' & 
        df['Spitfire'] == 'S' &
        df['Hurricane'] != 'H'))
    )
] | df[
    (
        ((df['Location'].str.contains('- Display') & 
        df['Lancaster'] != 'L' & 
        df['Dakota'] == 'D' & 
        df['Spitfire'] == 'SS' &
        df['Hurricane'] != 'H'))
     )]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用命令“pipenv run python”时出现回溯错误 - I get a traceback error when using the command "pipenv run python" 为什么我的 python 代码中出现 Traceback 错误 - Why am I getting Traceback error in my python code 第二次运行代码时Python中的Traceback错误 - Traceback Error in Python upon Second Run of code 当我执行我的 python 3 程序时出现回溯错误 - Traceback error when i execute my python 3 program Ubuntu运行时Python代码中的Traceback错误 - Traceback Error in Python Code when runs of Ubuntu 当我运行我的代码时,我在 Python 中遇到了一个巨大的错误 - When I Run My Code I Get A Huge Error In Python 我的代码中的 Python“回溯错误”,不确定如何解决 - Python "traceback error" in my code, unsure how to solve 当我启动这段代码时,我在 pygame 模块的代码中发现了错误 Traceback (last last call last) 的问题 - When I start this code, i found a problem with error Traceback (most recent call last) in my code with pygame module 当我尝试运行此Python程序时,出现回溯错误(最近一次调用最近)。 我想知道解决方案 - I get an error of traceback (most recent call last) when I try to run this Python program. I want to know the solution to this 当我尝试使用 droidcam 运行我的 CV2 python 代码时出现错误 - When I try to run my CV2 python code with droidcam I am getting error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM