我已经关闭了所有的括号/圆括号,但是Python没有识别到关闭的括号。

huangapple go评论114阅读模式
英文:

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[[&#39;Date&#39;, &#39;total_lmp&#39;]],
		data_western[&#39;total_lmp&#39;],
		data_aepgen[&#39;total_lmp&#39;],
		data_atsigen[&#39;total_lmp&#39;],
		data_chicagogen[&#39;total_lmp&#39;],
		data_chicago[&#39;total_lmp&#39;],
		data_dominion[&#39;total_lmp&#39;],
		data_eastern[&#39;total_lmp&#39;],
		data_nillinois[&#39;total_lmp&#39;],
		data_nj[&#39;total_lmp&#39;],
		data_ohio[&#39;total_lmp&#39;],
		data_aepdaytondata = pd.concat([data_westint[&#39;Date&#39;, &#39;total_lmp&#39;]]),
		data_western[&#39;total_lmp&#39;],
		data_aepgen[&#39;total_lmp&#39;],
		data_atsigen[&#39;total_lmp&#39;],
		data_chicagogen[&#39;total_lmp&#39;],
		data_chicago[&#39;total_lmp&#39;],
		data_dominion[&#39;total_lmp&#39;],
		data_eastern[&#39;total_lmp&#39;],
		data_nillinois[&#39;total_lmp&#39;],
		data_nj[&#39;total_lmp&#39;],
		data_ohio[&#39;total_lmp&#39;],
		data_aepdayton[&#39;total_lmp&#39;]
	],
	axis=1
)

</strike>

huangapple
  • 本文由 发表于 2023年7月7日 06:36:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632909.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定