![]() |
Indentation Error With If Else Statement - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Indentation Error With If Else Statement (/thread-28771.html) |
Indentation Error With If Else Statement - JoeDainton123 - Aug-02-2020 Hello all I was hoping someone could help with the following issue. I keep getting an indentation error when using an If else statement, my code is as follows:- t=0 while t < len(Data_Frame_Weekly_Tools_Report): data_frame_current = Data_Frame_Weekly_Tools_Report Data_Temp = Data_Frame_Weekly_Tools_Report.iloc[t,0] b=0 while b < len(data_frame_current): if Data_Temp == data_frame_current.iloc[b,0]: #do nothing else: data_frame_current.drop(index=[b,0]) b=b+1 t=t+1The error i get is:- I know the code looks unorthodox but i understand it but i just dont understand why the hell i keep getting this error????Can anyone help? Thank you. RE: Indentation Error With If Else Statement - Gribouillis - Aug-02-2020 # do nothing is not a statement. It is a comment. Python needs a statement after the if. Use pass
RE: Indentation Error With If Else Statement - JoeDainton123 - Aug-02-2020 Gribouillis That worked a charm. Thank you. RE: Indentation Error With If Else Statement - deanhystad - Aug-02-2020 This is one of those times when the Python error message isn't all that useful. I think this should be flagged as a syntax error, a floating else statement without a corresponding if or for. As in: if Data_Temp == data_frame_current.iloc[b,0]: else: data_frame_current.drop(index=[b,0])After all, "else" is the first statement following "if". But I guess indentation is either more important or is checked first. |