[英]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 DataFrame1:第二张作为数据帧
"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)
<class 'pandas.core.frame.DataFrame'>
not 'collections.OrderedDict'
<class 'pandas.core.frame.DataFrame'>
而不是'collections.OrderedDict'
pd.read_excel(file.xlsx, sheet_name=sheet1)
or pd.read_excel(file.xlsx, sheet_name=None)
if no sheet name providedpd.read_excel(file.xlsx, sheet_name=sheet1)
或pd.read_excel(file.xlsx, sheet_name=None)
如果没有提供工作表名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.