0
df = pd.read_csv("foo.csv")

# drop NaN
df = df.dropna()

df.iloc[0,0] = 1

# drop time
for i in range(3):
    df.iloc[0,0] = 2
    df.iloc[:,i] = datetime.strptime(df.iloc[:,i], "%Y-%m-%dT%H:%M:%S%z")

I get this error:

   File "accuracy.py", line 19
        df.iloc[0,0] = 2
         ^
  > SyntaxError: invalid character in identifier

I want to modify every value in the dataframe, so that I can work with the dates in there. However, when I use df.iloc in the for-loop, I get a similar Sytax Error to this one. I tried it again with simpler code, hence the df.iloc[0,0] = 2, but it gives the same error I would get from the other one. I also tried the code outside of the loop, and that doesn't result in an error, so I'm confused. I'm working from my terminal since I can't download the csv I'm working on, which makes debugging a little more interesting. Mostly because I cannot print things if the file does not compile. Any idea what the problem could be?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Ilse
  • 1
  • 1
  • Try commenting out those lines (the `df.iloc` ones), then retype (don't copy-paste anything; manually retype in a *text* editor) those two lines. – 9769953 Jan 12 '23 at 10:49
  • The top answer to [this question](https://stackoverflow.com/questions/14844687/invalid-character-in-identifier) list a potential cause. I won't flag it as a duplicate yet, but it may very well be that that's the issue. – 9769953 Jan 12 '23 at 10:50
  • Well, I just tried retyping it again and it somehow worked. I thought I did that, especially by adding the simple line, but maybe not. Thank you! – Ilse Jan 12 '23 at 11:04
  • Very likely then an invisible control character that made its way into your code. – 9769953 Jan 12 '23 at 11:05
  • I'll just delete the post then in a few minutes – Ilse Jan 12 '23 at 11:05
  • Or leave it up as a duplicate. I find deleting it always a shame, if it is/was relevant (even if just to you) and the problem solved. – 9769953 Jan 12 '23 at 11:07
  • Oh I'll do that then – Ilse Jan 13 '23 at 20:39

0 Answers0