简体   繁体   English

AttributeError: 'collections.OrderedDict' 对象没有属性 'iloc'

[英]AttributeError: 'collections.OrderedDict' object has no attribute 'iloc'

import pandas as pd 

file = 'D:/myproject/chatbot_database.xlsx'
xl = pd.read_excel(file)
print(xl)                                        #this prints fine     
print(xl.iloc[0, 1])                             #this throws an error

The error message is:错误信息是:

AttributeError: 'collections.OrderedDict' object has no attribute 'iloc' AttributeError: 'collections.OrderedDict' 对象没有属性 'iloc'

I have tried searching through stackoverflow and googled this for 2 days but i just don't seem to be able to get an answer so i am posting this question.我试过在 stackoverflow 中搜索并用谷歌搜索了 2 天,但我似乎无法得到答案,所以我发布了这个问题。 So the main issue is that this code works on my computer but it does not work on my friends computer.所以主要问题是这段代码在我的电脑上有效,但在我朋友的电脑上不起作用。 I tried to reinstall pandas hoping that that would fix the iloc issue since iloc is part of pandas but no avail.我试图重新安装熊猫,希望能解决 iloc 问题,因为 iloc 是熊猫的一部分,但无济于事。 Anyone has any idea what the issue is?任何人都知道问题是什么? or what other libraries may be missing?或者可能缺少哪些其他库?

Edited post below with screenshot below编辑下面的帖子,下面有截图

在此处输入图片说明

Reason is you forget mentioned sheet_name=None parameter in read_excel , what return OrderedDict , where keys are sheetnames and values are DataFames:原因是你忘了提到sheet_name=None参数read_excel ,什么返回OrderedDict ,其中键是sheetnames和值DataFames:

sheet_name : str, int, list, or None, default 0 sheet_name : str, int, list, or None, default 0

Strings are used for sheet names.字符串用于工作表名称。 Integers are used in zero-indexed sheet positions.整数用于零索引工作表位置。 Lists of strings/integers are used to request multiple sheets.字符串/整数列表用于请求多个工作表。 Specify None to get all sheets.指定无以获取所有工作表。

Available cases:可用案例:

Defaults to 0: 1st sheet as a DataFrame默认为 0:第 1 个工作表作为 DataFrame
1: 2nd sheet as a DataFrame 1:第二张作为数据帧
"Sheet1": Load sheet with name “Sheet1” “Sheet1”:加载名为“Sheet1”的工作表
[0, 1, "Sheet5"]: Load first, second and sheet named “Sheet5” as a dict of DataFrame [0, 1, "Sheet5"]: 加载第一个、第二个和名为“Sheet5”的工作表作为 DataFrame 的字典
None : All sheets.:所有工作表。

xl = pd.read_excel(file, sheet_name=None)
  1. first of all please put the exact error message.首先,请输入确切的错误信息。
  2. print(type(df)) it should return <class 'pandas.core.frame.DataFrame'> not 'collections.OrderedDict' print(type(df)) 它应该返回<class 'pandas.core.frame.DataFrame'>而不是'collections.OrderedDict'
  3. while reading mention sheetname pd.read_excel(file.xlsx, sheet_name=sheet1) or pd.read_excel(file.xlsx, sheet_name=None) if no sheet name provided在阅读时提及 sheetname pd.read_excel(file.xlsx, sheet_name=sheet1)pd.read_excel(file.xlsx, sheet_name=None)如果没有提供工作表名称
  4. Please go through documentation of any modules before using it请在使用前阅读任何模块的文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django AttributeError: &#39;collections.OrderedDict&#39; 对象没有属性 &#39;pk&#39; - Django AttributeError: 'collections.OrderedDict' object has no attribute 'pk' AttributeError: 'collections.OrderedDict' object 没有属性 'value_counts' - AttributeError: 'collections.OrderedDict' object has no attribute 'value_counts' 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: &#39;collections.OrderedDict&#39; 对象没有属性 &#39;split&#39; - AttributeError: 'collections.OrderedDict' object has no attribute 'split' “collections.OrderedDict”对象没有属性 - 'collections.OrderedDict' object has no attribute &#39;collections.OrderedDict&#39; 对象没有属性 &#39;pk&#39; - 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' Django - &#39;collections.OrderedDict&#39; 对象没有属性 &#39;headers&#39; - Django - 'collections.OrderedDict' object has no attribute 'headers' 如果不是 (target.size() == input.size()): AttributeError: 'collections.OrderedDict' object has no attribute 'size' 我收到此错误 - if not (target.size() == input.size()): AttributeError: 'collections.OrderedDict' object has no attribute 'size' I'm getting this error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM