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,
Solution 1:
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 : 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 1: 2nd sheet as a DataFrame "Sheet1": Load sheet with name “Sheet1” [0, 1, "Sheet5"]: Load first, second and sheet named “Sheet5” as a dict of DataFrame None: All sheets.
xl = pd.read_excel(file, sheet_name=None)
Solution 2:
- first of all please put the exact error message.
- print(type(df)) it should return
<class 'pandas.core.frame.DataFrame'>
not'collections.OrderedDict'
- while reading mention sheetname
pd.read_excel(file.xlsx, sheet_name=sheet1)
orpd.read_excel(file.xlsx, sheet_name=None)
if no sheet name provided - Please go through documentation of any modules before using it
Post a Comment for "Attributeerror: 'collections.ordereddict' Object Has No Attribute 'iloc'"