0

I am trying to use machine learning to predict students' future grade, but am stuck at the beginning.

Seems like pandas.read_csv cannot read psv file, I got:

df = pd.read_csv(‘training.psv’)
                             ^
SyntaxError: invalid character in identifier

How can I read psv file through python?

cs95
  • 379,657
  • 97
  • 704
  • 746
Roy
  • 11
  • 2
  • 1
    Your issue is wrongly trying to use `...` (backticks) instead of quotes ('...' or "...") around the filename. It has nothing whatsoever to do with the filetype (PSV). If has nothing specific to do with files, you would get the same error if you used backticks in a print statement. This is a simple typo. – smci May 06 '19 at 00:39
  • ...in fact they were Unicode quotes `U+2018,9`, which are also illegal for quoting a string. You can see this with `[ '{:02x}'.format(ord(c)) for c in "‘training.psv’" ]` from [this answer](https://stackoverflow.com/questions/12214801/print-a-string-as-hex-bytes) – smci May 06 '19 at 09:18
  • ...to which an existing duplicate question-and-answer is [this one](https://stackoverflow.com/a/26841280/202229) – smci May 06 '19 at 09:21

2 Answers2

2

The problem is in the quotes symbol. You should either use ' or ".

Try:

df = pd.read_csv('training.psv')
rafasan
  • 176
  • 8
1
pd.read_csv("training.psv", sep = "|", header = FALSE, stringsAsFactors = FALSE)

That should work

Atle Kristiansen
  • 707
  • 7
  • 28