File "C:\Users\万万众\PycharmProjects\pythonProject1\01.py", line 6 df = DataFrame(pd.read_excel('"C:\Users\万万众\Desktop\unsdg_2002_2021.csv"')) ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 3-4: truncated \UXXXXXXXX escape
时间: 2023-12-03 16:47:01 浏览: 127
python read excel.zip_excel读取_python excel_python_read_excel_pyt
这个错误通常是因为在文件路径中使用了反斜杠"\", 但是反斜杠在Python中被视为转义字符,需要将其替换为斜杠"/"或双反斜杠"\\".
你可以将文件路径修改为以下形式:
```python
df = DataFrame(pd.read_excel('C:/Users/万万众/Desktop/unsdg_2002_2021.csv'))
```
或者使用双反斜杠:
```python
df = DataFrame(pd.read_excel('C:\\Users\\万万众\\Desktop\\unsdg_2002_2021.csv'))
```
或者使用原始字符串:
```python
df = DataFrame(pd.read_excel(r'C:\Users\万万众\Desktop\unsdg_2002_2021.csv'))
```
阅读全文