I've been trying to open an excel file in python, but so far it has not worked. My code is the following:
import pandas as pd
from openpyxl.workbook import Workbook
df_excel = pd.read_excel('C:\Users\Adam Smith\Desktop\GPA Scale.xlsx')
print (df_excel)
The error I get is the following:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 12-13: truncated \UXXXXXXXX escape
I've tried the following but the error is still not fixed.
I tried to put double slashes as follows:
df_excel = pd.read_excel('C:\\Users\\Adam Smith\\Desktop\\GPA Scale.xlsx')
I got the following error when I put the double slashesOSError: [Errno 22] Invalid argument: '\u202aC:\\Users\\Adam Smith\\Desktop\\GPA Scale.xlsx
I tried to add an 'r' at the beginning of the line as follows:
df_excel = pd.read_excel(r'C:\Users\Adam Smith\Desktop\GPA Scale.xlsx')
I got the following error when I added the 'r'OSError: [Errno 22] Invalid argument: '\u202aC:\\Users\\Adam Smith\\Desktop\\GPA Scale.xlsx'
Lastly, I tried to change the backslash to forward slash as follows:
df_excel = pd.read_excel('C:/Users/Adam Smith/Desktop/GPA Scale.xlsx')
I got the following error when I changed it to a forward slash.
`OSError: [Errno 22] Invalid argument: '\u202aC:/Users/Adam Smith/Desktop/GPA Scale.xlsx'`
I'm confused as to why I keep getting the error. Any suggestions on fixing it would be appreciated.
Thanks