今天利用pandas讀取excel時,爆出如下錯誤:
代碼為:
import pandas as pd
db_eua=pd.read_excel('db_eua.xlsx',sheetname='EUA')
print(db_eua.read())
錯誤為:ImportError: No module named 'xlrd'
原來,pandas讀取excel文件,需要單獨的xlrd模塊支持。
然后又碰到錯誤:
Traceback (most recent call last):
File "C:/pylearn/usepan.py", line 4, in <module>
print(db_eua.read())
File "C:\Python35\lib\site-packages\pandas\core\generic.py", line 3081, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'read'
仔細一看,自己馬大哈了,因該是;head(),不是read()
修改后,運行結果如下;
Date Strip Price
0 2017-03-24 2017-03-17 4.78
1 2017-03-24 2017-12-17 4.86
2 2017-03-24 2017-12-18 4.91
3 2017-03-24 2017-12-19 4.98
4 2017-03-24 2017-12-20 5.10
