[英]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.