运行这部分代码时出现错误。尝试了一些现有的解决方案,但都没有帮助
elec_and_weather = pd.read_csv(r'C:\HOUR.csv', parse_dates=True,index_col=0)
# Add historic DEMAND to each X vector
for i in range(0,24):
elec_and_weather[i] = np.zeros(len(elec_and_weather['DEMAND']))
elec_and_weather[i][elec_and_weather.index.hour==i] = 1
# Set number of hours prediction is in advance
n_hours_advance = 24
# Set number of historic hours used
n_hours_window = 24
for k in range(n_hours_advance,n_hours_advance+n_hours_window):
elec_and_weather['DEMAND_t-%i'% k] = np.zeros(len(elec_and_weather['DEMAND']))'
我总是收到这个错误
for i in range(0,24):
File "<ipython-input-29-db3022a769d1>", line 1
for i in range(0,24):
^
SyntaxError: unexpected EOF while parsing
File "<ipython-input-25-df0a44131c36>", line 1
for k in range(n_hours_advance,n_hours_advance+n_hours_window):
^
SyntaxError: unexpected EOF while parsing
这SyntaxError: unexpected EOF while parsing
意味着在完成所有代码块之前,已到达源代码的末尾。代码块以类似如下的语句开头,for i in range(100):
并且随后至少需要一行包含其中应包含的代码的行。
好像您在ipython控制台中逐行执行程序。这适用于单个语句a = 3
,例如for循环,但不适用于代码块。请参见以下示例:
In [1]: for i in range(100):
File "<ipython-input-1-ece1e5c2587f>", line 1
for i in range(100):
^
SyntaxError: unexpected EOF while parsing
为避免此错误,您必须将整个代码块作为单个输入输入:
In [2]: for i in range(5):
...: print(i, end=', ')
0, 1, 2, 3, 4,
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句