英文:
I have closed all my brackets/parenthesis, but python isn't recognizing the closing bracket
问题
我已经设置好了其他一切,我的数据框架等。我已经使用了相同的过程,只是复制并粘贴了它(我需要为不同的数据集编写不同的代码,它们在后来有不同的要求)。
当我到达一个我重复使用的步骤时,我只是像以前许多次一样使用 pandas.concat
。
data = pd.concat([data_westint[['Date', 'total_lmp']], data_western['total_lmp'], data_aepgen['total_lmp'], data_atsigen['total_lmp'], data_chicagogen['total_lmp'], data_chicago['total_lmp'], data_dominion['total_lmp'], data_eastern['total_lmp'], data_nillinois['total_lmp'], data_nj['total_lmp'], data_ohio['total_lmp'], data_aepdaytondata = pd.concat([data_westint['Date', 'total_lmp']], data_western['total_lmp'], data_aepgen['total_lmp'], data_atsigen['total_lmp'], data_chicagogen['total_lmp'], data_chicago['total_lmp'], data_dominion['total_lmp'], data_eastern['total_lmp'], data_nillinois['total_lmp'], data_nj['total_lmp'], data_ohio['total_lmp'], data_aepdayton['total_lmp']], axis=1)
SyntaxError: closing parenthesis ')' does not match opening parenthesis '(' is the error I get
它说最后一个括号(在 , axis
之前的括号)没有闭合。
我尝试过在前面添加另一个括号,或者删除第一个括号,但都没有起作用。有什么建议吗?
英文:
I have everything else set up, my dataframes, etc. I have used this same process and simply copy and pasted it (I needed different code for different data sets, they had different requirements later on)
When I got to a step I have repeated, I am simply using pandas.concat
like I have used many times before.
data = pd.concat([data_westint[['Date', 'total_lmp']], data_western['total_lmp'], data_aepgen['total_lmp'], data_atsigen['total_lmp'], data_chicagogen['total_lmp'], data_chicago['total_lmp'], data_dominion['total_lmp'], data_eastern['total_lmp'], data_nillinois['total_lmp'], data_nj['total_lmp'], data_ohio['total_lmp'], data_aepdaytondata = pd.concat([data_westint['Date', 'total_lmp']], data_western['total_lmp'], data_aepgen['total_lmp'], data_atsigen['total_lmp'], data_chicagogen['total_lmp'], data_chicago['total_lmp'], data_dominion['total_lmp'], data_eastern['total_lmp'], data_nillinois['total_lmp'], data_nj['total_lmp'], data_ohio['total_lmp'], data_aepdayton['total_lmp']], axis=1)
SyntaxError: closing parenthesis ']' does not match opening parenthesis '(' is the error I get
It is saying the last bracket, (the one before , axis
) isn't closed.
I have tried adding another bracket in front, or removing the first bracket, but nothing works. Any advice?
答案1
得分: 2
看起来你有一个复制/粘贴的问题。你是不是想要做这个?
data = pd.concat(
[data_westint[['日期', '总LMP']],
data_western['总LMP'],
data_aepgen['总LMP'],
data_atsigen['总LMP'],
data_chicagogen['总LMP'],
data_chicago['总LMP'],
data_dominion['总LMP'],
data_eastern['总LMP'],
data_nillinois['总LMP'],
data_nj['总LMP'],
data_ohio['总LMP'],
data_aepdayton['总LMP']],
axis=1)
英文:
It looks like you have a copy/paste problem. Is this what you are trying to do?
data = pd.concat(
[data_westint[['Date', 'total_lmp']],
data_western['total_lmp'],
data_aepgen['total_lmp'],
data_atsigen['total_lmp'],
data_chicagogen['total_lmp'],
data_chicago['total_lmp'],
data_dominion['total_lmp'],
data_eastern['total_lmp'],
data_nillinois['total_lmp'],
data_nj['total_lmp'],
data_ohio['total_lmp'],
data_aepdayton['total_lmp']],
axis=1)
答案2
得分: 0
如果您将那个庞大的代码行分成多行,您将立即发现问题:
data = pd.concat(
[
data_westint[['Date', 'total_lmp']],
data_western['total_lmp'],
data_aepgen['total_lmp'],
data_atsigen['total_lmp'],
data_chicagogen['total_lmp'],
data_chicago['total_lmp'],
data_dominion['total_lmp'],
data_eastern['total_lmp'],
data_nillinois['total_lmp'],
data_nj['total_lmp'],
data_ohio['total_lmp'],
data_aepdaytondata = pd.concat( # 嗯,这是什么?
[
data_westint['Date', 'total_lmp']
],
data_western['total_lmp'],
data_aepgen['total_lmp'],
data_atsigen['total_lmp'],
data_chicagogen['total_lmp'],
data_chicago['total_lmp'],
data_dominion['total_lmp'],
data_eastern['total_lmp'],
data_nillinois['total_lmp'],
data_nj['total_lmp'],
data_ohio['total_lmp'],
data_aepdayton['total_lmp']
], # ???
axis=1
)
这是您写的内容。我只是添加了换行和缩进。
英文:
If you would have split that massive line of code into multiple lines, you would have immediately spotted the problem(s):
data = pd.concat(
[
data_westint[['Date', 'total_lmp']],
data_western['total_lmp'],
data_aepgen['total_lmp'],
data_atsigen['total_lmp'],
data_chicagogen['total_lmp'],
data_chicago['total_lmp'],
data_dominion['total_lmp'],
data_eastern['total_lmp'],
data_nillinois['total_lmp'],
data_nj['total_lmp'],
data_ohio['total_lmp'],
data_aepdaytondata = pd.concat( # Uh, what?
[
data_westint['Date', 'total_lmp']
],
data_western['total_lmp'],
data_aepgen['total_lmp'],
data_atsigen['total_lmp'],
data_chicagogen['total_lmp'],
data_chicago['total_lmp'],
data_dominion['total_lmp'],
data_eastern['total_lmp'],
data_nillinois['total_lmp'],
data_nj['total_lmp'],
data_ohio['total_lmp'],
data_aepdayton['total_lmp']
], # ???
axis=1
)
This is what you wrote. I just added newlines and indentation.
<strike>
Seems like you wanted:
data = pd.concat(
[
data_westint[['Date', 'total_lmp']],
data_western['total_lmp'],
data_aepgen['total_lmp'],
data_atsigen['total_lmp'],
data_chicagogen['total_lmp'],
data_chicago['total_lmp'],
data_dominion['total_lmp'],
data_eastern['total_lmp'],
data_nillinois['total_lmp'],
data_nj['total_lmp'],
data_ohio['total_lmp'],
data_aepdaytondata = pd.concat([data_westint['Date', 'total_lmp']]),
data_western['total_lmp'],
data_aepgen['total_lmp'],
data_atsigen['total_lmp'],
data_chicagogen['total_lmp'],
data_chicago['total_lmp'],
data_dominion['total_lmp'],
data_eastern['total_lmp'],
data_nillinois['total_lmp'],
data_nj['total_lmp'],
data_ohio['total_lmp'],
data_aepdayton['total_lmp']
],
axis=1
)
</strike>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论