Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';收藏。订购信息和#x27;对象没有属性_Python_Excel_Pandas_Dataframe_Import - Fatal编程技术网

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'
我已经阅读了熊猫的资料。阅读excel
pandas.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()