I sum up my above comments here in hope that it helps next users.
The problem is that your filepath is a string that contains the backslash character (\
) since you are on Windows.
(Note : this wasn't visible in your sample code, but my guess is that you simplified the path, since this solution worked).
And this character is also used to encode special characters. For instance, "\n" corresponds to line break.
So if your path is, say, "C:\Users\Aarush\Documents\mnist_train.csv"
, Python is trying to figure out what character the \U
stands for. This can have many unexpected effects.
To avoid this and open your file properly, ensure that you add a "r" before the path, like this:
mnist = pd.read_csv(r"C:\Users\Aarush\Documents\mnist_train.csv")
This "r" stands for "raw" and means you turned your string into a raw string where all characters must be interpreted literally (and not as escape characters).
- if you still have the error, this comes from the CSV file parsing: in that case, also check the separator (comma, semicolon... : this is the parameter "sep" in
pd.read_csv()
) and the file encoding (parameter "encoding" in pd.read_csv
, usually "utf-8")