How to fix unicode error

Hello, dear Psychopy users and coders!
How can I fix unicode error? ( ‘unicodeescape’ codec can’t decode bytes in position 2-3)
I have tried multiple ways mentioned in discussions, but it did not work.
This is part of the code:

import random
import pandas as pd
from psychopy import visual, event, core

Specify the file path of the Excel file

file_path = ‘C:\Users\USR\Desktop\thesis\third\experiment\sentences.xls’

Load the sentences from an Excel file

df = pd.read_excel(‘sentences.xls’, sheet_name=‘sheet1’)
sentences = df[‘sentences’].tolist()

Hello,
This error doesn’t have anything to do with PsychoPy; you can search for it online and see some solutions:

In your example, the following works:

file_path = ‘C:\Users\USR\Desktop\thesis\third\experiment\sentences.xls’
# --->
file_path = r"C:\Users\USR\Desktop\thesis\third\experiment\sentences.xls"

Let me know if it fixed your problem :slight_smile:
Chen

Thank you for your help.
I appreciate it.
It worked well.

1 Like