关于Pandas读取Excel文件
前置条件
需要先安装openpyxl
或者xlrd
建议安装指定版本,至少xlrd
一定要指定安装版本,不然会报一些意外的错误,且指定xlrd
的版本一般在1.2.0
,其他的可能会有一些其他错误,亲测。
pip install openpyxl==3.0.10 -i https://pypi.douban.com/simple
pip install xlrd==1.2.0 -i https://pypi.douban.com/simple
读取格式
一般默认的Pandas读取的Excel文件格式为.xlsx
结尾的,但是也会有xls
结尾的,所以具体的读取时候的代码如下所示:
读取.xlsx
结尾的文件时候:
import pandas as pd
df = pd.read_excel('xxxx.xlsx')
读取.xls
结尾的文件时候:
import pandas as pd
df = pd.read_csv('xxxx.xls')
一定要注意一下!!!