python - Pandas 找不到 .xlsx 文件。有没有办法让它工作?
问题描述
由于某些原因,python 无法加载我的数据,我正在尝试使用 pandas 从 excel 文件中加载数据。
kg = pd.read_excel('C:\Users\Desktop\NewData','Sales')
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape***
解决方案
由于转义参数,python 试图将路径中的 '\U' 理解为 unicode 字符。为避免这种情况,请尝试在字符串之前添加 r ,这意味着 raw 以停止字符串格式化。或者只对每个 '\' 使用 '\',因为字符串格式需要两个反斜杠来检索一个反斜杠。前任:
kg = pd.read_excel(r'C:\Users\Desktop\NewData','Sales')
或者
kg = pd.read_excel('C:\\Users\\Desktop\\NewData','Sales')
推荐阅读
- excel - Excel公式静态值增量
- azure - Azure 表存储数据建模注意事项
- adfs - 在已加入域的服务器中启用 adfs
- c# - 如何在 c# 中使用模拟/服务帐户(如在 Exchange api 中)读取同一域中所有用户的 gmail
- c# - 打开带有未解码 URL 的 chrome 进程
- sharepoint - 共享点信息路径表格
- apache-felix - Liferay 7.1 中 apache felix Web 控制台包的需求和用途是什么
- jquery - 模式关闭后在 Datatables.net 网格中单击行
- javascript - Plaid 的“Auth”特性中的“user”对象指的是什么?
- c# - 有没有办法将这个查询重写为更“LINQ-ier”?