pandas read excel文件碰到的一個小問題


今天利用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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM