【发布时间】:2023-03-18 21:26:01
【问题描述】:
我正在尝试将数据从 excel 读取到 pandas。我得到的文件来自api并且没有保存(访问文件需要特殊权限,所以我不想保存它)。当我尝试从文件中读取 excel 时
with open('path_to_file') as file: re = pd.read_excel(file)
我得到了错误
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x98 in position 10: invalid start byte
当我在文件位置输入路径时,一切正常
re = pd.read_excel('path-to-exactly-the-same-file')
有没有办法通过pandas读取excel而不保存和输入路径?
【问题讨论】:
-
尝试将文件读取为字节:
with open('path_to_file', 'rb') as file