ALWAYS GETTING ERROR WHILE RUNNING THIS PART OF THE CODE.Checked the existing solutions none helped
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']))'
I am always getting this error
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
The
SyntaxError: unexpected EOF while parsing
means that the end of your source code was reached before all code blocks were completed. A code block starts with a statement likefor i in range(100):
and requires at least one line afterwards that contains code that should be in it.It seems like you were executing your program line by line in the ipython console. This works for single statements like
a = 3
but not for code blocks like for loops. See the following example:To avoid this error, you have to enter the whole code block as a single input:
My syntax error was semi-hidden in an f-string
should be
It didn't have the PyCharm spell-check-red line under the error.
It did give me a clue, yet when I searched on this error message, it of course did not find the error in that bit of code above.
Had I looked more closely at the error message, I would have found the '' in the error. Seeing Line 1 was discouraging and thus wasn't paying close attention :-( Searching for
yielded nothing. Searching for
yielded practically everything :-\
If I can help you avoid even a minute longer of deskchecking your code, then mission accomplished :-)