Home > database >  python pandas AttributeError: 'dict' object has no attribute 'head'
python pandas AttributeError: 'dict' object has no attribute 'head'

Time:11-11

df = pd.read_excel(download_path, sheet_name=None)
l = df.values.tolist()

on this I am getting error uiltin_function_or_method' object has no attribute 'tolist'

when I do something like this

  print(df.head())

I get error like AttributeError: 'dict' object has no attribute 'head'

what thing I am doing wrong here ?

version of libraries

pandas==1.5.1 openpyxl xlrd==2.0.1

CodePudding user response:

When reading an excel file with pandas, if you set sheet_name=None as a parameter for pd.read_excel you will get a dictionary mapping between sheet names in the excel file and their corresponding DataFrames (as hinted in the documentation).

You can use the following template to extract the relevant DataFrames

mapping = pd.read_excel(download_path, sheet_name=None)
for sheet_name in mapping:
    df = mapping[sheet_name]
    l = df.values.tolist()
  • Related