Python ';收藏。订购信息和#x27;对象没有属性
运行上述代码后,我得到以下结果:Python ';收藏。订购信息和#x27;对象没有属性,python,excel,pandas,dataframe,import,Python,Excel,Pandas,Dataframe,Import,运行上述代码后,我得到以下结果: 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&q
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()
sheet_name=None将不起作用,您可以像这样组合读取excel文件行
collections.OrderedDict object has no attribute 'head'
我已经阅读了熊猫的资料。阅读excelpandas.read_excel
方法将返回数据帧或数据帧的dict
当您设置sheet\u name=None
时,您将得到以数据帧dict的形式返回的所有工作表。此dict
的键将是图纸名称
因此,在您的代码片段中,dfs
是一个dict
而不是DataFrames
。显然,dict
没有head
方法。您的代码应该是这样的dfs[sheet\u name].head()
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()