[英]'collections.OrderedDict' object has no attribute
import pandas as pd
xl=pd.ExcelFile('/Users/denniz/Desktop/WORKINGPAPER/FDIPOLITICS/python.xlsx')
dfs = pd.read_excel(xl,sheet_name=None, dtype={'COUNTRY':str,'YEAR': int, 'govtcon':float, 'trans':float},na_values = "Missing")
dfs.head()
After running the code above i got the following:运行上面的代码后,我得到以下信息:
collections.OrderedDict object has no attribute 'head'
sheet_name = None will not work and you can combine reading excel file lines like this. sheet_name = None 将不起作用,您可以像这样组合读取 excel 文件行。
import pandas as pd
import xlrd
dfs=pd.read_excel('/Users/denniz/Desktop/WORKINGPAPER/FDIPOLITICS/python.xlsx',sheet_name=0, dtype={'COUNTRY':str,'YEAR': int, 'govtcon':float, 'trans':float},na_values = "Missing")
dfs.head()
I have read the API reference of pandas.read_excel
.我已经阅读了
pandas.read_excel
的API 参考。 pandas.read_excel
method will return DataFrame or dict of DataFrames . pandas.read_excel
方法将返回DataFrame 或 DataFrames dict 。
As you set sheet_name=None
, you will get All sheets returned in the form of a dict of DataFrames .当您设置
sheet_name=None
,您将以DataFrames 的字典形式返回所有工作表。 The key of this dict
will be the sheet name.此
dict
的键将是工作表名称。
So in your code snippet, dfs
is a dict
not a DataFrames
.所以在你的代码片段中,
dfs
是一个dict
而不是DataFrames
。 Obviously, dict
has no head
method.显然,
dict
没有head
方法。 Your code should be like this dfs[sheet_name].head()
.你的代码应该是这样的
dfs[sheet_name].head()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.