Chan Sec 3 Unit 14

Hi - This is really difficult.  I'm trying to implement this code on the ASX banks but when I add the read file code I get an error message like this:



File "<string>", line 26

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 6-7: malformed \N character escape



My code looks like this:

-- coding: utf-8 --


# 03_mean_reversion_on_triplets.pf

# FOUR BANKS CBA, ANZ, NAB, WBC

# For data manupulation
import numpy as np
import pandas as pd

# For plotting
import matplotlib.pyplot as plt
#ERROR matplotlib inline
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

# For checking cointegration
# ERROR from johansen import coint_johansen

import warnings
warnings.filterwarnings('ignore')

# Read data from CSV file
anz = pd.read_csv("myData\ANZ.csv", index_col =0)
cba = pd.read_csv("myData\CBA.csv", index_col =0)
nab = pd.read_csv("myData\NAB.csv", index_col =0)
wbc = pd.read_csv("myData\WBC.csv", index_col =0)

print(anz)
print(cba)
#ERROR print(nab)
print(wbc)

I thought the course was meant to put you in a position to be able to implement in this way but if I get two errors every section in a programming language I am new to it will take forever to do this.

Can you help me cut through this and get code that works which I can then edit.

Thanks

Hello Stephen,



The issue is because of the fact that the 7th character \N in the path of your file "myData\NAB.csv" is actually a special character. You need to "escape" your strings before you use this path. The escaped version of this path string will be:



"myData\NAB.csv" instead. This makes sure \N isn't treated as a special character. 



Read this answer as well.