網站首頁 編程語言 正文
panda讀取中文xlsx文件
1、數據為中文內容,xlsx文件保存。
2、直接讀取文件出錯(Python報錯:pandas.errors.ParserError: Error tokenizing data. C error: Expected 3……),將xlsx文件后綴保存為csv,仍出現格式問題(xlsx不能為多表,左下角可以切換多個窗口的那種),后**將xlsx文件另存為csv**解決此問題。
3、讀取csv文件出現編碼問題(UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb3 in position 0: invalid start byte),在讀取文件時改編碼content = pd.read_csv(‘news.csv’,encoding=‘gbk’)
解決pandas讀取xlsx時報錯
Must explicitly set engine if not passing in buffer or path for io.
今天在用低版本的pandas==0.24.2時,讀取xlsx文件報錯。
pd.read_excel(xlsx_file_IO_string) # xlsx IO流
Must explicitly set engine if not passing in buffer or path for io.
查看了源代碼,如果未指定engine,那么默認使用xlrd來讀,而且我本地的xlrd==1.2.0,所以不存在xlrd版本問題。另外又嘗試指定了engine=openpyxl,仍然不能解決讀取xlsx文件錯誤的問題。確定是pandas版本過低導致的問題,有條件的可以升級pandas版本,沒條件的繼續往下看。
使用BytesIO對象,聲明流為bytes類型,成功解決問題。
from pandas.io.common import BytesIO
import pandas as pd
pd.read_excel(BytesIO(content))) # 此處centent為你的xlsx文件內容
原文鏈接:https://blog.csdn.net/weixin_39965184/article/details/109235376
相關推薦
- 2022-12-01 .NET?Core部署為Windows服務的詳細步驟_實用技巧
- 2022-02-17 H5移動端點擊出現背景藍色框的解決方案
- 2022-07-14 C++實現一個簡單的線程池的示例代碼_C 語言
- 2022-12-15 Go字典使用詳解_Golang
- 2022-10-05 Android開發Activity毛玻璃背景效果_Android
- 2022-08-15 Android?Gradle模塊依賴替換使用技巧_Android
- 2022-04-12 C++中標準線程庫的基本使用介紹_C 語言
- 2022-10-10 python使用pandas讀寫excel文件的方法實例_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支