在查看了读取url链接的不同方法后,指向.xls文件,我决定使用xlrd.
我很难将'xlrd.book.Book'类型转换为'pandas.DataFrame'
我有以下内容:
import pandas
import xlrd
import urllib2
link ='http://www.econ.yale.edu/~shiller/data/chapt26.xls'
socket = urllib2.urlopen(link)
#this line gets me the excel workbook
xlfile = xlrd.open_workbook(file_contents = socket.read())
#storing the sheets
sheets = xlfile.sheets()
Run Code Online (Sandbox Code Playgroud)
我想把最后一张sheets和导入作为一个pandas.DataFrame关于如何实现这一点的任何想法?我试过了,pandas.ExcelFile.parse()但它想要一个excel文件的路径.我当然可以将文件保存到内存然后解析(使用tempfile或者其他),但我正在尝试遵循pythonic指南并使用可能已经写入pandas的功能.
一如既往地非常感谢任何指导.