![](/img/trans.png)
[英]pd.read_excel throws PermissionError if file is open in Excel
[英]pd.read_excel throws UnicodeDecodeError
我正在嘗試從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?
缺少的部分是 open 中'rb'
with open('path_to_file', 'rb') as file:
re = pd.read_excel(file)
將文件視為二進制文件。 想法取自錯誤 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.