从桌面上的子文件夹读取XLSX数据

2024-04-19 12:09:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用pandas和jupyter笔记本从桌面上的子文件夹将excel文件读入数据框。该文件位于我的桌面上的一个文件夹中,该文件夹名为“Data”,子文件夹名为“KN Data”,子文件夹名为“New Files”,文件名为“Customers.xlsx”

以下是我正在尝试的代码:

df_customers = pd.read_excel (r"C:/Users/Zach/Desktop/Data/KN-Data/New-Files/Customers.xlsx")

错误是

[Errno 2] No such file or directory: 'C:/Users/Zach/Desktop/Data/KN-Data/New-Files/Customers.xlsx'

Tags: 文件文件夹pandasnewdatajupyterfilesxlsx
1条回答
网友
1楼 · 发布于 2024-04-19 12:09:50

尝试使用双反斜杠而不是单正斜杠。我总是用双反斜杠,这对我很有用

您的代码应该是这样的:

df_customers = pd.read_excel (r"C:\\Users\\Zach\\Desktop\\Data\\KN-Data\\New-Files\\Customers.xlsx")

相关问题 更多 >