为什么 pandas.read_excel 不会运行? [英] Why won't pandas.read_excel run?
问题描述
我正在尝试使用 pandas.read_excel 但我不断收到'module' object has no attribute 'read_excel'"作为我终端中的错误,如图所示
I am trying to use pandas.read_excel but I keep getting " 'module' object has no attribute 'read_excel' " as an error in my terminal as shown
File "read.py", line 9, in <module>
cols = pd.read_excel('laucnty12', 'Poverty Data', index_col='State', \\ na_values=['NA'])
AttributeError: 'module' object has no attribute 'read_excel'
我试过 pd.read_excel() 和 pd.io.parsers.read_excel() 但得到同样的错误.我安装了 python 2.7,pandas 的其他部分工作正常,例如 xls.parse 和 read_csv.我的代码如下:
I have tried pd.read_excel() and pd.io.parsers.read_excel() but get the same error. I have python 2.7 installed and other parts of pandas work fine such as xls.parse and read_csv. My code is below:
import pandas as pd
from pandas import *
xls = pd.ExcelFile('laucnty12.xls')
data = xls.parse('laucnty12', index_col=None, na_values=['NA'])
cols = pd.read_excel('laucnty12', 'Poverty Data', index_col='State', na_values=['NA'])
print cols
推荐答案
df = pd.read_excel(filepath + 'Result.xlsx')
检查excel文件的扩展名是xls
还是xlsx
,然后在查询中添加相同的内容.我试过了,现在工作正常.
Check whether the extension of excel file is xls
or xlsx
then add the same in the query. I tried and its is working fine now.
这篇关于为什么 pandas.read_excel 不会运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!