SyntaxError: unexpected EOF while parsing

Python

I am getting error while running this part of the code. tried some of the existing solutions, none of them 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 

1
Answers

Replies


First of all, make sure that proper indentation is in place for your code. The EOF error occurs when it reaches the end of your source code before all the code blocks are completed.



Make sure that you are not executing this code in the iPython console. Because it does not work for a block of code, i.e., for the loop in your code. You should enter the whole code block as a single unit.


 

 
 

If you want to unleash your potential in this competitive field, please visit the Python course page for more information, where you can find the Python tutorials and Python frequently asked interview questions and answers as well.

 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.