简体   繁体   English

“collections.OrderedDict”对象没有属性

[英]'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_excelAPI 参考 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.

相关问题 'collections.OrderedDict' 对象没有属性 'pk' - django rest 框架 - 'collections.OrderedDict' object has no attribute 'pk' - django rest framework 预训练的 model 错误? 'collections.OrderedDict' object 没有属性 'eval' - pretrained model error ? 'collections.OrderedDict' object has no attribute 'eval' AttributeError: 'collections.OrderedDict' object 没有属性 'train' - AttributeError: 'collections.OrderedDict' object has no attribute 'train' Django - AttributeError: 'collections.OrderedDict' 对象没有属性 'id' - Django - AttributeError: 'collections.OrderedDict' object has no attribute 'id' AttributeError: 'collections.OrderedDict' 对象没有属性 'split' - AttributeError: 'collections.OrderedDict' object has no attribute 'split' AttributeError: 'collections.OrderedDict' 对象没有属性 'iloc' - AttributeError: 'collections.OrderedDict' object has no attribute 'iloc' Django - 'collections.OrderedDict' 对象没有属性 'headers' - Django - 'collections.OrderedDict' object has no attribute 'headers' AttributeError: 'collections.OrderedDict' object 没有属性 'size' - AttributeError: 'collections.OrderedDict' object has no attribute 'size' Django AttributeError: 'collections.OrderedDict' 对象没有属性 'pk' - Django AttributeError: 'collections.OrderedDict' object has no attribute 'pk' AttributeError: 'collections.OrderedDict' object 没有属性 'value_counts' - AttributeError: 'collections.OrderedDict' object has no attribute 'value_counts'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM